属性(Property)类型定义了对描述属性的结构体objc_property的不透明的句柄。
typedef struct objc_property *Property;
您可以使用函数class_copyPropertyList和protocol_copyPropertyList来获得类(包括范畴类)或者协议类中的属性列表:
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)
typedef struct objc_property *Property;
您可以使用函数class_copyPropertyList和protocol_copyPropertyList来获得类(包括范畴类)或者协议类中的属性列表:
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)
objc_property_t *protocol_copyPropertyList(Protocol *proto, unsigned int *outCount)
在使用这些方法的过程中,千万不要忘了一件事,那就是内存释放问题
容易造成这方面错误的有两种原因
一、当我们习惯了ARC的自动释放机制,所以会不经意的遗漏这方面的问题
记得在最后使用free来释放
二、大家在写代码的过程,基本都是网上搜索,参考已有的代码
而网上的代码有很大的问题,在代码的完整性方面有所欠缺,比如以下的代码:
上面的代码就缺少释放的功能,大家在借鉴时就会调入坑中