catagory添加属性
1 #import <Foundation/Foundation.h> 2 #import <objc/runtime.h> 3 4 @interface NSObject (CategoryWithProperty) 5 6 /** 7 * 要在Category中扩展的属性 8 */ 9 @property (nonatomic, strong) NSObject *property; 10 11 @end 12 13 @implementation NSObject (CategoryWithProperty) 14 15 - (NSObject *)property { 16 return objc_getAssociatedObject(self, @selector(property)); 17 } 18 19 - (void)setProperty:(NSObject *)value { 20 objc_setAssociatedObject(self, @selector(property), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 21 } 22 23 @end