NSObject添加属性

来源:互联网 发布:java权限系统设计 编辑:程序博客网 时间:2024/06/15 10:20

/**
 * @file AnimateObject.h
 * @brief 为NSobject添加customAnimating属性
 */

@interface NSObject(CustomAnimate)


@property (retain, nonatomic) NSNumber *customAnimating;

@end

/**
 * @file AnimateObject.m
 */

#import "AnimateObject.h"
#import <objc/runtime.h>

static const void *customAnimatingKey = &customAnimatingKey;

@implementation NSObject(CustomAnimate)

- (NSNumber *)customAnimating {
    return objc_getAssociatedObject(self, customAnimatingKey);
}

- (void)setCustomAnimating:(NSNumber *)animating{
    objc_setAssociatedObject(self, customAnimatingKey, animating, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end


0 0
原创粉丝点击