- 获取类的属性列表
unsigned int count
objc_property_t *propertyList = class_copyPropertyList(self.class, &count)
for (unsigned int i = 0
const char *propertyName = property_getName(propertyList[i])
NSLog(@"propertyname; %@", [NSString stringWithUTF8String:propertyName])
}
- 获取所有成员变量
unsigned int count
Ivar *ivarList = class_copyIvarList(self.class, &count)
for (int i = 0
Ivar ivar = ivarList[i]
const char *ivarName = ivar_getName(ivar)
NSLog(@"ivarName: %@", [NSString stringWithUTF8String: ivarName])
}
- 获取所有方法
unsigned int count
Method *methodList = class_copyMethodList(self.class, &count)
for (int i = 0
Method method = methodList[i]
SEL methodName = method_getName(method)
NSLog(@"methodName: %@", NSStringFromSelector(methodName))
}
- 获取当前所遵循的所有协议
unsigned int count
__unsafe_unretained Protocol **protocolList = class_copyProtocolList([self class], &count)
for (int i = 0
Protocol *protocol = protocolList[i]
const char *protocolName = protocol_getName(protocol)
NSLog(@"protocolName: %@", [NSString stringWithUTF8String:protocolName])
}