当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Why did not have three parameter objc_msgSend() method?

问题描述:

I used Xcode7 #import < objc/message.h>. I want to use this function. but this function is only empty parameter method . I found this function takes three parameters in the document

网友答案:

If you want to use objc_msgSend you have to cast it to the right type. I post you an example on how I've just use it in one of my projects

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL{
SEL wk_sel = NSSelectorFromString(@"loadData:MIMEType:characterEncodingName:baseURL:");
((void (*)(id, SEL, id, id, id, id))objc_msgSend)(self,wk_sel,data,MIMEType,textEncodingName,baseURL);
}

If you prefer a cleaner sintax you can use a function pointer. If your method is declared as:

- (void)doSomething:(id)arg0 withArgument:(float)arg1 err:(NSError **)err{}

You have to do something like this:

void (*objc_msgSendTyped)(id self, SEL _cmd, id something, float arg1, NSError**error) = (void*)objc_msgSend;
objc_msgSendTyped(self, @selector(doSomething:withArgument:err:), foo, bar, &error);
分享给朋友:
您可能感兴趣的文章:
随机阅读: