#import"BaseClass.h"
@interfaceBaseClass (BaseCategary)
@property(nonatomic,copy)NSString* string;
- (void)BaseCategaryMethod;
@end
#import"BaseClass+BaseCategary.h"
#import
NSString*constkDHStyleKey =@"kDHStyleKey";
@implementationBaseClass (BaseCategary)
@dynamicstring;
- (void)BaseCategaryMethod {
NSLog(@"BaseCategaryMethod");
}
- (void)setString:(NSString*)string {
// self.a = a;
objc_setAssociatedObject(self, (__bridgeconstvoid*)(kDHStyleKey), string,OBJC_ASSOCIATION_COPY);
}
- (NSString*)string {
// return self.a;
return objc_getAssociatedObject(self, (__bridgeconstvoid*)(kDHStyleKey));
}
使用:
#import"BaseClass+BaseCategary.h"
BaseClass* baseClass = [[BaseClassalloc]init];
[baseClassBaseCategaryMethod];
baseClass.string=@"aaaaad";
NSLog(@"baseClass.string == %@",baseClass.string);