标签:ios开发入门
方法选择器
1` instancesRespondToSelector
SEL sel = @selector(study); if([TRStudent
instancesRespondToSelector:sel] ==
YES)//判定TRStudent类中是否有sel这个实例方法(该语句只能判断实例方法是否存在) {
NSLog(@"类TRStudent中有方法study"); }
2` respondsToSelector
if ([stu respondsToSelector:@selector(learn)] ==YES) {
NSLog(@"对象stu可以调用learn方法"); }
协议选择器
3` conformsToProtocol
TRStudent *stu = [[TRStudent alloc]initWithName:@"张三"
andID:1000]; if ([TRStudent
conformsToProtocol:@protocol(NSCopying)]==YES) { ... }
网友评论