-
遍歷對象的所有@property屬性戴尸,賦初始值‘uu’
圖1.png - 代碼如下:
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屬性矿瘦,但是不全面。下面是我查到一片針對我這個缺陷描述的鏈接侯勉。
點擊