用法
//動態(tài)創(chuàng)建屬性
objc_setAssociatedObject(self, (__bridge const void *)(KpropertyKey), temp.copy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//獲取動態(tài)創(chuàng)建的屬性值
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);//注意釋放內(nèi)存
//原有方法
Method old = class_getInstanceMethod(self, @selector(setImage:));
//新方法
Method new = class_getInstanceMethod(self, @selector(DD_setImage:));
//交叉方法
method_exchangeImplementations(old, new);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者