objective-c
#import <UIKit/UIKit.h>
@interface UILabel (Name)
@property (nonatomic, strong) NSString * name;
@end
#import "UILabel+Name.h"
#import <objc/runtime.h>
@implementation UILabel (Name)
static char *nameKey = "name";
- (NSString *)name {
return objc_getAssociatedObject(self, nameKey);
}
- (void)setName:(NSString *)name {
objc_setAssociatedObject(self, nameKey, name, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
swift
privatevar key:Int = 0
extension FofTrendResp {
var pointState:NSMutableArray {
get {
return (objc_getAssociatedObject(self, &key) as? NSMutableArray)!
}
set(newValue) {
objc_setAssociatedObject(self, &key, newValue, objc_AssociationPolicy(rawValue: objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN.rawValue)!)
}
}
}