I've been using objc_setAssociatedObject() this way:
objc_setAssociatedObject(myObject, @"myKey1", obj2, OBJC_ASSOCIATION_ASSIGN);
In particular, my key is a character string, so the compiler uses the pointer to that string. I specify the same character string in objc_getAssociatedObject():
objc_getAssociatedObject(myObject, @"myKey1").
I've been using this scheme for a long time without any problem. However, the examples on SO use a pointer to a static variable, so I now realize that my method might be incorrect. The compiler uses the same pointer each time, so it's always worked.
Is my method okay? It seems equivalent to using a pointer to a static string. Under what circumstances might the compiler store two different copies of my key?