如何在运行的时候动态获取到该属性的类型呢?
此方法获取属性的特性:property_copyAttributeValue
unsigned int a;
objc_property_t * result = class_copyPropertyList(object_getClass(k), &a);
for (unsigned int i = 0; i < a; i++) {
objc_property_t o_t = result[i];
NSLog(@"name: %@", [NSString stringWithFormat:@"%s", property_getName(o_t)]);
NSLog(@"att: %@", [NSString stringWithFormat:@"%s", property_getAttributes(o_t)]);
}
2018-06-07 15:32:59.252063+0800 runtime[17026:450201] name: height_i
2018-06-07 15:32:59.252217+0800 runtime[17026:450201] att: Ti,V_height_i
2018-06-07 15:32:59.252316+0800 runtime[17026:450201] name: height_d
2018-06-07 15:32:59.252365+0800 runtime[17026:450201] att: Td,V_height_d
2018-06-07 15:32:59.252404+0800 runtime[17026:450201] name: height_f
2018-06-07 15:32:59.252434+0800 runtime[17026:450201] att: Tf,V_height_f
2018-06-07 15:32:59.252452+0800 runtime[17026:450201] name: weight
2018-06-07 15:32:59.252498+0800 runtime[17026:450201] att: T@"NSNumber",R,N,V_weight
2018-06-07 15:32:59.252518+0800 runtime[17026:450201] name: name
2018-06-07 15:32:59.252546+0800 runtime[17026:450201] att: T@"NSString",&,V_name
2018-06-07 15:32:59.252573+0800 runtime[17026:450201] name: family
2018-06-07 15:32:59.252612+0800 runtime[17026:450201] att: T@"NSString",&,V_family
如上可以打印特性值:
image.png
image.png
官方文档为:* Declared Properties
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有