标签:
.h文件
//分类的头文件
@interface ClassName (CategoryName)
@property (nonatomic, strong) NSString *str;//此为新增的属性
//此为新增的属性
@end
.m文件
//实现文件
#import "ClassName + CategoryName.h"
#import <objc/runtime.h>
static void *strKey = &strKey;
@implementation ClassName (CategoryName)
-(void)setStr:(NSString *)str
{
objc_setAssociatedObject(self, & strKey, str, OBJC_ASSOCIATION_COPY);
}
-(NSString *)str
{
return objc_getAssociatedObject(self, &strKey);
}
@end
标签:
原文地址:http://www.cnblogs.com/making/p/5687642.html