#pragma mark 实例变量列表 - (void)ivarList { unsigned int count; Ivar *ivarList = class_copyIvarList([NSObject class], &count); for (unsigned int i = 0; i < count; i++) { Ivar myIvar = ivarList[i]; const char *ivarName = ivar_getName(myIvar); NSLog(@"%d)ivar == %@", i, [NSString stringWithUTF8String:ivarName]); } free(ivarList); }
2)objc_property_list
1 2 3 4 5 6 7 8 9 10
#pragma mark 属性列表 - (void)propertyList { unsigned int count; objc_property_t *propertyList = class_copyPropertyList([NSObject class], &count); for (unsigned int i = 0; i < count; i++) { const char *propertyName = property_getName(propertyList[i]); NSLog(@"%d)propertyName == %@", i, [NSString stringWithUTF8String:propertyName]); } free(propertyList); }
3)objc_method_list
1 2 3 4 5 6 7 8 9 10
#pragma mark 方法列表 - (void)methodList { unsigned int count; Method *methodList = class_copyMethodList([NSObject class], &count); for (unsigned int i = 0; i < count; i++) { Method method = methodList[i]; NSLog(@"%d)method == %@", i, NSStringFromSelector(method_getName(method))); } free(methodList); }
4)objc_protocol_list
1 2 3 4 5 6 7 8 9 10 11
#pragma mark 协议列表 - (void)protocolList { unsigned int count; __unsafe_unretained Protocol *protocolList = class_copyProtocolList([NSObject class], &count); for (unsigned int i = 0; i < count; i++) { Protocol *myProtocal = protocolList[i]; const char *protocolName = protocol_getName(myProtocal); NSLog(@"%d)protocol == %@", i, [NSString stringWithUTF8String:protocolName]); } free(protocolList); }