Home » IOS » Associated Ob

Associated Ob

Associated Objects - or Associative References, as they were initially known - is the feature of Objective-C 2 runtime, introduced in OS X Snow Leopard (IOS 4), specifically


@interface NSObject (AssociatedObject) 
@property (nonatomic, strong) id associatedObject;
@end

NSObject+AssociatedObject.m


@implementation NSObject (AssociatedObject) 
@dynamic associatedObject;
- - (void) setAssociatedObject: (id) object {
Objc_setAssociatedObject (self, @selector (associatedObject), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- - (id) associatedObject {
return objc_getAssociatedObject (self, @selector (associatedObject));
}

Latest