Last Updated: February 25, 2016
·
755
· jaykz52

Mixin properties on ObjC classes via the ObjC runtime

// header
@interface NSObject (PornName)

@property (nonatomic, strong) NSString *pornName;

@end

// implementation
#import <objc/runtime.h>

static char const * const PornNameKey = "PornNameKey";

@implementation NSObject (PornName)

@dynamic pornName;

- (NSString *)pornName {
    return objc_getAssociatedObject(self, PornNameKey);
}

- (void)setPornName:(NSString *)pornName {
    objc_setAssociatedObject(self, PornNameKey, pornName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end