objc_property_attribute_t 的value和name
2016-03-06 21:04
344 查看
获取一个属性的attributes
objc_property_attribute_t的value和name
动态添加属性
@interface person : NSObject @property (nonatomic, strong) NSString *name; @end int main(){ unsigned int outCount = 0; objc_property_t *properties = class_copyPropertyList([person class], &outCount); for(int i = 0; i < outCount; i++){ unsigned int count = 0; objc_property_attribute_t *attributes = property_copyAttributesList(properties[i], &count); for(int j = 0; j < count; j++){ <span style="white-space:pre"> </span>NSLog(@"attribute.name = %s, attribute.value = %s", attributes[j].name, attributes[j].value); } } return 0; }
objc_property_attribute_t的value和name
常用attribute | name | value |
nonatomic | "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 |
@interface person : NSObjec{ NSString *_name; } int main(){ objc_property_attribute_t nonatomic = {"N", ""}; objc_property_attribute_t strong = {"&", ""}; objc_property_attribute_t type = {"T", "@\"NSString\""}; objc_property_attribute_t ivar = {"V", "_name"}; objc_property_attribute_t attributes[] = {nonatomic, strong, type, ivar}; BOOL result = class_addProperty([person class], "name", attributes, 4); }
相关文章推荐
- easyUI confirm消息框的OK和cancel按钮的修改
- (java)Increasing Triplet Subsequence
- 使用Arduino读取噪声传感器分贝值
- 批判性思维——Asking The Right Questions
- 骨骼算法,仿生中的外观
- View Programming Guide for iOS 学习笔记_3
- Android Volley完全解析(三),定制自己的Request
- 关于UITableView 的一些重用技术注意点
- hdu1509 Windows Message Queue(优先队列水)
- leetcode52 N-Queens II
- (java)Unique Binary Search Trees
- POJ 3458 Colour Sequence
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
- StringBuffer和StringBuilder存在的作用是什么
- blade and soul pvp guide
- blade and soul races guide
- UI设计 - iOS
- UI设计 - Web
- UI设计 - PPT
- STL与泛型编程<三>:deque