Add a variable to a class instance at runtime: Difference between revisions
Content added Content deleted
(jq) |
|||
Line 659:
#import <objc/runtime.h>
static void *fooKey = &fooKey; // one way to define a unique key is a pointer variable that points to itself
int main (int argc, const char *argv[]) {
Line 667:
// set
objc_setAssociatedObject(e,
// get
NSNumber *associatedObject = objc_getAssociatedObject(e,
NSLog(@"associatedObject: %@", associatedObject);
|