-
遍历对象的所有@property属性,赋初始值‘uu’
- 代码如下:
import <objc/runtime.h>
-(void)defaultValueMethod:(id) sender
{ int i; int propertyCount = 0; objc_property_t propertyList = class_copyPropertyList([sender class], &propertyCount); for ( i=0; i < propertyCount; i++ ) { objc_property_t thisProperty = propertyList + i; const char propertyName = property_getName(thisProperty); NSString *string = [NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding]; [self setValue:@"uu" forKey:string]; NSLog(@"Person has a property: '%s'", propertyName); }
}
- 虽然遍历了对象@property属性,但是不全面。下面是我查到一片针对我这个缺陷描述的链接。
点击