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
Written by Jason Kozemczak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#