#import <Foundation/Foundation.h>
@interface NSObject (Common)
@property (nonatomic,copy) NSString* name;
@property (nonatomic,assign) NSInteger aID;
@end
#import "NSObject+Common.h"
#import <objc/runtime.h>
static NSString* nameKey = @"nameKey";
static NSString* aIDKey = @"aIDKey";
@implementation NSObject (Common)
- (void)setName:(NSString*)name{
objc_setAssociatedObject(self,&nameKey, name, OBJC_ASSOCIATION_COPY);
}
- (NSString*)name{
return objc_getAssociatedObject(self, &nameKey);
}
- (void)setAID:(NSInteger)aID{
objc_setAssociatedObject(self, &aIDKey, [NSString stringWithFormat:@"%ld",(long)aID], OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSInteger)aID{
return [objc_getAssociatedObject(self, &aIDKey) integerValue];
}
@end
网友评论