本文共 1642 字,大约阅读时间需要 5 分钟。
?Objective-C??????????????????????????????????????????????????????????????????
??????????????????????Objective-C?????????????
#import@interface Animal : NSObject- (void)speak;- (void)jump;@end
??????????????Animal????NSObject????????????- (void)speak;?- (void)jump;????????????????
?????????Animal??????dog?cat???????????????
??selector???????????@selector(speak)??????????
??selector???performSelector:withObject:inResponses:timeout:??????????????????
??????????????????????
#import@interface Animal : NSObject- (void)speak;- (void)jump;@end@implementation Animal- (void)speak { NSLog(@"Animal speak");}- (void)jump { NSLog(@"Animal jump");}@endint main() { @autoreleasepool { Animal *dog = [[Animal alloc] init]; Animal *cat = [[Animal alloc] init]; SEL speakSelector = @selector(speak); SEL jumpSelector = @selector(jump); [dog performSelector:speakSelector withObject:nil inResponses:nil timeout:5]; [dog performSelector:jumpSelector withObject:nil inResponses:nil timeout:5]; [cat performSelector:speakSelector withObject:nil inResponses:nil timeout:5]; [cat performSelector:jumpSelector withObject:nil inResponses:nil timeout:5]; } return 0;}
???????@interface?????Animal?????- (void)speak;?- (void)jump;?
??????@implementation?????speak?jump??????????????
???main??????Animal??dog?cat??????selector``speakSelector?jumpSelector?
?????????performSelector:withObject:inResponses:timeout:??????speak?jump???????????????
???????????Objective-C?????????????????????????????????????
转载地址:http://ahifk.baihongyu.com/