IOS objc_msgSend 32位和64位
阿新 • • 發佈:2017-12-21
padding com cto style else 執行 蘋果官方 sele orm
objc_msgSend(obj,normalSelector,command) 只支持32位如果在64位可能出現類的賦值出錯 如:
假如 obj 是CDVPlugin類 normalSelector 是一個方法選擇器(即@selector(方法名))該方法的參數是 command(CDVInvokedUrlCommand類)
在32位上面執行後成功把command的原屬性傳遞過去了,但是在64位會發現command的class變為了CDVPlugin(我項目上實際發生並測出來的)
修改方法:
變為: ((void(*)(id,SEL,id))objc_msgSend)(obj,normalSelector,command);
蘋果官方推薦:
- (int) doSomething:(int) x { ... }
- (void) doSomethingElse {
int (*action)(id, SEL, int) = (int (*)(id, SEL, int)) objc_msgSend;
action(self, @selector(doSomething:), 0);
}
可以簡寫為: ((int(*)(id,SEL,int)))objc_msgSend)(self,@selector(doSomething:),0);
親測有效
IOS objc_msgSend 32位和64位