MessageSend:
1,在方法沒有實現(xiàn)的時候不會報錯蹄溉,是因為OC運行時機制,在運行的時候才會動態(tài)監(jiān)測灵妨,而c或者C++這類語言必須在定義的時候明確指明其類型财饥,而不是等到運行過程動態(tài)監(jiān)測,這類語言叫做靜態(tài)語言
[cat play];
[cat playWithKid:@"zhangdanfeng"];
[IMCat play];
[IMCat playWithKid:@"zhangdanfeng"];
2,用稍微底層的方法performSeletor實現(xiàn):
[cat performSelector:@selector(play)];
[cat performSelector:@selector(playWithKid:) withObject:@"zhangdanfeng"];
Class catClass = [cat class];
[catClass performSelector:@selector(play)];
[[IMCat class] performSelector:@selector(playWithKid:) withObject:@"zhangdanfeng"];
3,底層實際就是轉(zhuǎn)成了messageSend方法,貌似iOS8之后底層方法被禁用了务嫡,如果需要打開甲抖,需要在Build Settings中禁用enable strict checking of Obj-c messageSend calls選項
objc_msgSend(cat, @selector(play));
objc_msgSend(cat, @selector(playWithKid:),@"zhangdanfeng");
objc_msgSend([IMCat class], @selector(play));
objc_msgSend([IMCat class], @selector(playWithKid:),@"zhangdanfeng");
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者