美文网首页
runtime应用1

runtime应用1

作者: i大猫哥 | 来源:发表于2016-05-10 13:12 被阅读29次
  1. 遍历对象的所有@property属性,赋初始值‘uu’


    图1.png
  2. 代码如下:

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

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

相关文章

网友评论

      本文标题:runtime应用1

      本文链接:https://www.haomeiwen.com/subject/hrkyrttx.html