1. performSelector:object
performSelector在运行时调用方法,由于编译期间不会做校验,调用前最好做- (BOOL)respondsToSelector:(SEL)aSelector
检查。
弊端:参数传递只能是对象,不能传递基本数据类型,而且不能满足多个参数的传递。
2. objc_msgSend
objc_msgSend() 是performSelector :withObject 方法的底层实现,可以接受基础数据类型的参数。
调用错误:
-
兼容64位
#if __LP64__ objc_msgSend(self,selector, arg); #else ((void(*)(id, SEL, float))objc_msgSend)(self,selector, arg); #endif
-
Too many arguments to function call, expected 0, have 4
Build Setting--> Apple LLVM 7.1 - Preprocessing--> Enable Strict Checking of objc_msgSend Calls 改为 NO