#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// 动态类型检测 :响应方法
Animal *ani = [Dog new];
SEL s1 = @selector(eat);
// 1)通过performSelector响应无参的方法
if ([ani respondsToSelector:s1]) {
[ani performSelector:s1]; // 作用,响应方法 没有参数
} else{
NSLog(@"该对象不能调用此方法");
}
// 2)通过performSelector witOobject响应有参的方法
SEL s2 = @selector(eat:);
[ani performSelector:s2 withObject:@"一块"];
// 3)通过performSelector: withObject: withObject:响应有里两个参的方法
[ani performSelector:@selector(eat:andFoodName:) withObject:@"他" withObject:@"tang"];
}
return 0;
}
响应有参方法
最新推荐文章于 2022-11-03 16:46:40 发布