标签:
默认类别时无法添加属性的,但可以动态添加,利用runtime机制
#import
static const void * externVariableKey =&externVariableKey;
@implementation NSObject (Category)
@dynamic variable;
- (id) variable
{
return objc_getAssociatedObject(self, externVariableKey);
}
- (void)setVariable:(id) variable
{
objc_setAssociatedObject(self, externVariableKey, variable, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
标签:
原文地址:http://www.cnblogs.com/chunxin/p/5629516.html