博客> 判断一个类是否有某一个属性
判断一个类是否有某一个属性
2018-10-18 20:21 评论:1 阅读:627 千年雪域
属性
  • (BOOL)hasDelegate { unsigned int outCount = 0; objc_property_t properties = class_copyPropertyList([_currentPopView class], &outCount); BOOL flag; for (int i = 0; i < outCount; i++) { objc_property_t property = properties[i]; NSString propertyNameStr = [NSString stringWithUTF8String:property_getName(property)]; if ([propertyNameStr rangeOfString:@"delegate"].location != NSNotFound) { flag = YES; break; } } free(properties); return flag; }
收藏
1
sina weixin mail 回到顶部