objc_property_attribute_t

来源:互联网 发布:python 高斯卷积 编辑:程序博客网 时间:2024/06/06 16:31

[objc] view plain copy
  1. @interface person : NSObject  
  2. @property (nonatomicstrongNSString *name;  
  3. @end  
  4.   
  5. int main(){  
  6.   unsigned int outCount = 0;  
  7.   objc_property_t *properties = class_copyPropertyList([person class], &outCount);  
  8.   for(int i = 0; i < outCount; i++){  
  9.     unsigned int count = 0;  
  10.     objc_property_attribute_t *attributes = property_copyAttributesList(properties[i], &count);  
  11.     for(int j = 0; j < count; j++){  
  12.    <span style="white-space:pre"> </span>NSLog(@"attribute.name = %s, attribute.value = %s", attributes[j].name, attributes[j].value);   
  13.     }  
  14.   }  
  15.   return 0;  
  16. }  



objc_property_attribute_t的value和name

常用attributenamevaluenonatomic"N"""strong/retain"&"""weak"W"""属性的类型type"T""@TypeName", eg"@\"NSString\""属性对应的实例变量Ivar"V""Ivar_name", eg "_name"readonly"R"""getter"G""GetterName", eg"isRight"setter"S""SetterName", eg"setName"assign/atomic默认即为assign和retain 

动态添加属性

[objc] view plain copy
  1. @interface person : NSObjec{  
  2.   NSString *_name;  
  3. }  
  4. int main(){  
  5.   objc_property_attribute_t nonatomic = {"N"""};  
  6.   objc_property_attribute_t strong = {"&"""};  
  7.   objc_property_attribute_t type = {"T""@\"NSString\""};  
  8.   objc_property_attribute_t ivar = {"V""_name"};  
  9.   objc_property_attribute_t attributes[] = {nonatomicstrong, type, ivar};  
  10.   BOOL result = class_addProperty([person class], "name", attributes, 4);  

 转载地址:http://blog.csdn.net/myzlk/article/details/50815381

0 0
原创粉丝点击