Skip to content

Instantly share code, notes, and snippets.

@derrh
Created June 25, 2013 20:21
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 derrh/5862005 to your computer and use it in GitHub Desktop.
Save derrh/5862005 to your computer and use it in GitHub Desktop.
Synthesize + objc_get/setAssociatedObject
#import <objc/runtime.h>
#define SYNTHESIZE(class, getter, setter) \
static const void *getter##PropertyKey = &getter##PropertyKey;\
- (type *)getter { \
return objc_getAssociatedObject(self, getter##PropertyKey); \
} \
\
- (void)setter:(class *object) { \
objc_setAssociatedObject(self, getter##PropertyKey, object, OBJC_ASSOCIATION_RETAIN);\
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment