Skip to content

Instantly share code, notes, and snippets.

@dodikk
Last active January 1, 2016 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodikk/8100423 to your computer and use it in GitHub Desktop.
Save dodikk/8100423 to your computer and use it in GitHub Desktop.
Object Association misuse
static char ownershipsKey; // one for all objects
@implementation NSObject (Ownerships)
//should not autorelease returned value
- (NSMutableArray *)lazyOwnerships
{
NSMutableArray *result = objc_getAssociatedObject(self, &ownershipsKey);
if (!result) {
result = [NSMutableArray new];
// array instance per object
objc_setAssociatedObject(self,
&ownershipsKey,
result,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment