clang编译后的attribute属性
clang -rewrite-objc main.m -o main.cpp编译后生成的main.cpp文件中含有attribute
@property(nonatomic,copy)NSString *nickName;
@property(nonatomic,strong)NSString *name;
static struct /*_prop_list_t*/ {
unsigned int entsize; // sizeof(struct _prop_t)
unsigned int count_of_properties;
struct _prop_t prop_list[2];
} _OBJC_$_PROP_LIST_DCPerson __attribute__ ((used, section ("__DATA,__objc_const"))) = {
sizeof(_prop_t),
2,
{{"nickName","T@\"NSString\",C,N,V_nickName"},
{"name","T@\"NSString\",&,N,V_name"}}
}
查阅官方文档
获取某个对象的成员变量
/*
property_getAttributes(<#objc_property_t _Nonnull property#>)
class_copyPropertyList(<#Class _Nullable __unsafe_unretained cls#>, <#unsigned int * _Nullable outCount#>)
*/
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(pClass, &outCount);
for (i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));
}
//输出
nickName T@"NSString",C,N,V_nickName
name T@"NSString",&,N,V_name
打印出来的attribute分别代表什么呢?
T:type类型 NSString 类型
C:copy
N:nonatomic
V:variable变量