I have the following:
static char associated_obj_key;
id anObj;
NSMutableArray *a = [[NSMutableArray alloc] init];
objc_setAssociatedObject(anObj, &associated_obj_key, a, OBJC_ASSOCIATION_RETAIN);
[a release];
And I’d like to know: how to add objects to the NSMutableArray inside an associative reference for the anObj object? Is it such a thing even possible?
Can I even do something like [objc_getAssociatedObject(anObj, &associated_obj_key) addObject:something];?
Yes, but you would have to have the same key all over the places. As using an address of some static variable is indeed a recommended way, I suggest factoring out the single method for obtaining a reference of an associated object (creating if necessary). I use the following: