How to #import <NSObjCRuntime.h> to use objc_msgSend
I'd like to import runtime's header to use objc_msgSend but I'm getting:
error: NSObjCRuntime.h: No such file or directory
Should I add somethi开发者_如何学运维ng to the header search path?
You need to include <objc/message.h>
(you'll find the related headers in /usr/include/objc
) and link to the objc
(/usr/lib/libobjc.dylib
) library.
#import <Foundation/NSObjCRuntime.h>
does work
but you probably need
#import <objc/runtime.h>
like this Apple example does
upd: since iOS 7 #import <Foundation/NSObjCRuntime.h>
replaced to #import <objc/NSObjCRuntime.h>
but i recommend to use #import <objc/runtime.h>
anyway
When using Xcode 6 and later, you will get an error after #include<objc/message.h>
. It can be resolved like this
#include <objc/message.h>
void foo(void *object) {
typedef void (*send_type)(id, SEL, int);
send_type func = (send_type)objc_msgSend;
func(object, sel_getUid("foo:"), 5);
}
http://devstreaming.apple.com/videos/wwdc/2014/417xx2zsyyp8zcs/417/417_whats_new_in_llvm.pdf
精彩评论