runtime应用1

  1. 遍历对象的所有@property属性,赋初始值‘uu’


    runtime应用1_第1张图片
    图1.png
  2. 代码如下:

import

-(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); }
}

  1. 虽然遍历了对象@property属性,但是不全面。下面是我查到一片针对我这个缺陷描述的链接。
    点击

你可能感兴趣的:(runtime应用1)