u_int count =0;
Ivar *ivars = class_copyIvarList([NSNotificationCenter class], &count);
for(int i =0; i < count; i++) {
Ivar ivar = ivars[i];
NSLog(@"第%d个成员变量%s", i, ivar_getName(ivar));
}
u_int count1 =0;
objc_property_t *ts = class_copyPropertyList([Persion class], &count1);
for(int i =0; i < count1; i++) {
objc_property_t p = ts[i];
NSLog(@"第%d个属性%s", i, property_getName(p));
}
当一个类里边的属性使用class修饰的时候是无法获取到任何数据的 如:
@property (class, nonatomic, strong) NSString *age;
此时就无法获取到age属性, 也无法获取到get,set方法
u_int count2 =0;
Method *ms = class_copyMethodList([NSNotificationCenter class], &count2);
for(int i =0; i < count2; i++) {
Method m = ms[i];
NSLog(@"第%d个方法%s", i, method_getName(m));
}
网友评论