(1)類裏面的方法都是被轉換成SEL變量進行存儲的。
(2)放類聲明一個對象,對象調用方法的時候,系統會被這個方法轉換成SEL,然後拿這個SEL到類方法中去匹配。
(3)我們可以自己手動把方法轉換成SEL,然後用這個SEL去查找方法。
- #import <Foundation/Foundation.h>
- #import "Person.h"
- int main(int argc, const charchar * argv[]) {
- @autoreleasepool {
- Person *p1=[[Person alloc]init];
- //正常方法,需要把eat轉換成SEL,然後去匹配查找
- [p1 eat];
- //利用SEL,先我們自己把eat轉換成SEL,然後用這個SEL去找
- SEL aaa=@selector(eat);
- [p1 performSelector:aaa];
- //合併寫成
- [p1 performSelector:@selector(eat)];
- }
- return 0;
- }