Skip to content

Instantly share code, notes, and snippets.

@samkaufman
Created February 12, 2013 17:10
Show Gist options
  • Select an option

  • Save samkaufman/4771420 to your computer and use it in GitHub Desktop.

Select an option

Save samkaufman/4771420 to your computer and use it in GitHub Desktop.
An Xcode snippet implementing a category property that wraps an associated object. (Instance variables in categories, basically.)
static const void *<#Capitalized name#>AssociationKey;
- (<#Type#> *)<#Name#> {
return objc_getAssociatedObject(self, &<#Capitalized name#>AssociationKey);
}
- (void)set<#Name#>:(<#Type#> *)newObject {
objc_setAssociatedObject(self, &<#Capitalized name#>AssociationKey, newObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment