iOS-给Category添加属性

声明文件

#import 

@interface NSObject (SendInfo)

@property (nonatomic,assign) id sendInfo;

@end

实现文件

#import "NSObject+SendInfo.h"
#import 
static void * kSendInfoKey = &kSendInfoKey;
@implementation NSObject (SendInfo)

@dynamic sendInfo;

- (id)sendInfo{
    return objc_getAssociatedObject(self, kSendInfoKey);
}

- (void)setSendInfo:(id)sendInfo{
    return objc_setAssociatedObject(self, kSendInfoKey, sendInfo, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end

你可能感兴趣的:(iOS-给Category添加属性)