Skip to content

Instantly share code, notes, and snippets.

@jamiepinkham
Created January 26, 2011 20:39
Show Gist options
  • Save jamiepinkham/797403 to your computer and use it in GitHub Desktop.
Save jamiepinkham/797403 to your computer and use it in GitHub Desktop.
@implementation UIControl (RepresentedObject)
static char kRepresentedObjectKey;
- (void)setRepresentedObject:(id<NSObject>)object{
id assocObject = [self representedObject];
if(assocObject != object){
[assocObject release];
objc_setAssociatedObject(self, &kRepresentedObjectKey, object, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
- (id<NSObject>)representedObject{
return objc_getAssociatedObject(self, &kRepresentedObjectKey);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment