一、首先创建一个runtime的测试用例
@interface RtTest : NSObject
@property (nonatomic, assign) int sidNum;
@end
@implementation RtTest
@end
二、调用获取runtime的property
unsigned int count = 0;
objc_property_t* propertys = class_copyPropertyList([RtTest class], &count);
for (unsigned int i = 0; i < count; i++) {
objc_property_t property = propertys[i];
assert(property != nil);
const char* name = property_getName(property);
NSLog(@"name: %s", name);
NSString* attrs = @(property_getAttributes(property));
NSLog(@"artStr: %@", attrs);
}
得到的输出结果是:
name:sidNum
artStr:Ti,N,V_sidNum
解析:其中T是类型i 代表int;V是名字接着sidNum,N非原子性nonatomic
三、结论:
1.property_getName意如其名
2.property_getAttributes,其作用就是用来获取属性的真实类型。
NSString *const TypeInt = @"i"; 整数类型
NSString *const TypeShort = @"s"; 双字节类型
NSString *const TypeFloat = @"f"; float 浮点型
NSString *const TypeDouble = @"d"; double 双精度浮点型
NSString *const TypeLong = @"l"; long 长整型
NSString *const TypeLongLong = @"q";
NSString *const TypeChar = @"c"; char 单字节类型
NSString *const TypeBOOL1 = @"c"; bool 类型
NSString *const TypeBOOL2 = @"b"; bool 类型
NSString const TypePointer = @""; 指针类型
NSString *const TypeIvar = @"^{objc_ivar=}";
NSString *const TypeMethod = @"^{objc_method=}"; oc 方法类型
NSString *const TypeBlock = @"@?"; oc 闭包类型
NSString *const TypeClass = @"#"; oc class 类类型
NSString *const TypeSEL = @":"; oc slector 触发器方法类型
NSString *const TypeId = @"@"; oc 泛型id类型
NSString *const TypeShort = @"s"; 双字节类型
NSString *const TypeFloat = @"f"; float 浮点型
NSString *const TypeDouble = @"d"; double 双精度浮点型
NSString *const TypeLong = @"l"; long 长整型
NSString *const TypeLongLong = @"q";
NSString *const TypeChar = @"c"; char 单字节类型
NSString *const TypeBOOL1 = @"c"; bool 类型
NSString *const TypeBOOL2 = @"b"; bool 类型
NSString const TypePointer = @""; 指针类型
NSString *const TypeIvar = @"^{objc_ivar=}";
NSString *const TypeMethod = @"^{objc_method=}"; oc 方法类型
NSString *const TypeBlock = @"@?"; oc 闭包类型
NSString *const TypeClass = @"#"; oc class 类类型
NSString *const TypeSEL = @":"; oc slector 触发器方法类型
NSString *const TypeId = @"@"; oc 泛型id类型