ios 利用runtime打印类的所有属性
来源:互联网 发布:人工智能有关英语作文 编辑:程序博客网 时间:2024/05/29 17:19
1. 你可以用下面这段代码打印一个类的属性列表:
id tfClass = objc_getClass("userClass");unsigned int outCount, i;objc_property_t *properties = class_copyPropertyList(tfClass, &outCount);for (i = 0; i < outCount; i++) { objc_property_t property = properties[i]; fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));}
2. 属性类型字符串说明
你可以使用 property_getAttributes 方法来获取属性的名字、@encode类型字符串,以及属性的其他属性。
字符串以T开头,然后是 @encode 类型和逗号,最后是V和实例变量的名字。在这之中,属性由以下这些描述符指定:
const char *property_getAttributes(objc_property_t property)1
你可以用方法 class_getProperty 和 protocol_getProperty 获取一个类或协议的指定名字的属性的引用:
objc_property_t class_getProperty(Class cls, const char *name)objc_property_t protocol_getProperty(Protocol *proto, const char *name, BOOL isRequiredProperty, BOOL isInstanceProperty)
你可以使用 property_getName 来获取属性名:
const char *property_getName(objc_property_t property)
你可以这样获取属性列表:
id LenderClass = objc_getClass("Lender");unsigned int outCount;objc_property_t *properties = class_copyPropertyList(LenderClass, &outCount);
你可以使用 class_copyPropertyList 和 protocol_copyPropertyList 方法获取一个类、类别或者协议的属性列表:
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)objc_property_t *protocol_copyPropertyList(Protocol *proto, unsigned int *outCount)
属性声明
当编译器遇到属性声明(参见《The Objective-C Programming Language》中的属性声明),它会为这个类、类别或者协议产生一些描述性的 metadata。你可以通过一些方法访问这些metadata,这些方法能够通过类或者协议的名字查询属性,获取属性的类型,以及拷贝属性的属性。属性声明的列表对每个类和协议都适用。
属性类型和方法
Property 结构定义了属性描述符的handle。
typedef struct objc_property *Property;
0 0
- ios 利用runtime打印类的所有属性
- 利用反射打印对象所有属性的工具类
- golang打印所有的runtime调用栈
- 通过runtime获取一个类的所有属性
- 高效开发iOS系列(runtime篇) -- debug模式下使用po命令打印model的属性和值(runtime + debugDescription)
- OC 利用runtime获得类的属性和方法名字
- ios 通过runtime 获取类对象的所有子类
- 通过标准的Runtime API(C函数)打印UIKit中UIView的所有变量、属性以及方法
- iOS开发runtime给工程所有UITextfield属性赋初值
- iOS的runtime获取类的属性的数据类型
- 利用runtime添加属性
- iOS 利用runtime实现的Method Swizzling
- 打印对象的所有属性或方法
- 利用反射得出某个类的所有属性
- 利用反射得出某个类的所有属性
- 利用JAVA反射技术查找一个类的所有属性
- 利用JAVA反射技术查找一个类的所有属性
- 利用JAVA反射技术查找一个类的所有属性
- 如何在原有的iOS项目中添加cordova
- 加工生产调度(Johnson算法 双机流水作业调度问题)
- Pyqt5系列(九)-基本布局管理
- (BFS)广度优先搜索例子:迷宫,寻找连块数
- JavaScript设计模式——单例模式
- ios 利用runtime打印类的所有属性
- JAVA中字节流与字符流的区别详解
- 常见排序算法汇总与分析(上)(交换排序与插入排序)
- 使用apt-get下载出错,Media change: please insert the disc labeled.
- 洛谷 P1071 潜伏者
- Swift 滑块 UISlider
- matlab读取avi视频问题总结(结合别人的解决方法)
- Junit 单元测试 @Before @After。。。
- 关于内存管理思考方式的一些学习总结