unsigned int count = 0;
Ivar *ivarList = class_copyIvarList([self.person class], &count);
for (int i = 0; i < count; i++) {
Ivar ivar = ivarList[i];
const char * name = ivar_getName(ivar);
NSLog(@"%s", name);
}
self.person有一个只读的属性名称,我覆盖了名称的get
- (NSString *)name {
return @"";
}
然后,我无法通过class_copyIvarList找到它。
我无法理解这一点。
你给出了setter方法的定义,你还没有在Person
类中创建ivar。因此,班上没有name
ivar。
要么创建一个像ivar
@implementation Person
@synthesize name = _name;
- (NSString *)name {
return @"";
}
或者检查class_copyIvarList
类属性而不是实例变量(ivars)
unsigned int count = 0;
objc_property_t *propertyList = class_copyPropertyList([self.person class], &count);
for (int i = 0; i < count; i++) {
objc_property_t property = propertyList[i];
const char * propertyName = property_getName(property);
NSLog(@"%s", propertyName);
}