用法
//动态创建属性
objc_setAssociatedObject(self, (__bridge const void *)(KpropertyKey), temp.copy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//获取动态创建的属性值
objc_getAssociatedObject(self, (__bridge const void *)(KpropertyKey));
unsigned int count = 0;
objc_property_t *properties = class_copyPropertyList(self, &count);
NSMutableArray *temp = [NSMutableArray array];
for (unsigned int i = 0; i<count; i++) {
objc_property_t property = properties[i];
const char *cStr = property_getName(property);
NSString *ocStr = [NSString stringWithCString:cStr encoding:NSUTF8StringEncoding];
[temp addObject:ocStr];
}
free(properties);//注意释放内存
//原有方法
Method old = class_getInstanceMethod(self, @selector(setImage:));
//新方法
Method new = class_getInstanceMethod(self, @selector(DD_setImage:));
//交叉方法
method_exchangeImplementations(old, new);
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。