.H 文件
#import <UIKit/UIKit.h>
@interface UIViewController (statistics)
@property (nonatomic, strong, readwrite) id myCustomProperty;
@end
.M 文件
static void * myCustomCategoryPorpertyKey = (void *)@"myCustomCategoryPorpertyKey";
- (id)myCustomProperty {
return objc_getAssociatedObject(self, myCustomCategoryPorpertyKey);
}
- (void)setMyCustomProperty:(id)myCustomProperty {
objc_setAssociatedObject(self, myCustomCategoryPorpertyKey, myCustomProperty, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}