- 获取类的属性列表
unsigned int count;
objc_property_t *propertyList = class_copyPropertyList(self.class, &count);
for (unsigned int i = 0; i < count; i++) {
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; i < count; i ++) {
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; i < count; i ++) {
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; i < count; i ++) {
Protocol *protocol = protocolList[i];
const char *protocolName = protocol_getName(protocol);
NSLog(@"protocolName: %@", [NSString stringWithUTF8String:protocolName]);
}
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END