SEL (@selector) 原理及本质
#import <Foundation/Foundation.h>
#import "Person.h"
int main()
{
Person *p = [[Person alloc] init];
[p test2];
NSString *name = @"test2";
SEL s = NSSelectorFromString(name);
[p performSelector:s];
SEL s = @selector(test3:);
[p performSelector:s withObject:@"456"];
[p test2];
return 0;
}
@interface Person : NSObject
+ (void)test;
- (void)test2;
- (void)test3:(NSString *)abc;
@end
@implementation Person
+ (void)test
{
NSLog(@"test-----");
}
- (void)test2
{
NSString *str = NSStringFromSelector(_cmd);
NSLog(@"调用了test2方法-----%@", str);
}
- (void)test3:(NSString *)abc
{
NSLog(@"test3-----%@", abc);
}
@end