objective c - How do I use objc_setAssociatedObject/objc_getAssociatedObject inside an object? -


itemprop = "text">

If I use objc_setAssociatedObject / objc_getAssociatedObject to store a duplicate instance variable in a setter method inside a class implementation, I How to use the key in the gator method since any variables declared in the setter method have been out of the purview of the clogging method?

Edit: To clarify, if I was using the following method, then tell me that STRING_KEY should declare me so that I can do it both in the Setter and Recipient Methods I can use

  @ Interface NSVU (simulate) - (zero) set simulated string: (nssting *) migration; - (NSString *) fake string; @end @implementation NSView (simulateVar) - (zero) setSimualtedString: (NSString *) myString {objc_setAssociatedObject (auto, & amp; STRING_KEY, myString, OBJC_ASSOCIATION_RETAIN); } - (NSString *) simulated string {return (nsstring *) ozjak_gate abuserated object (self, and STRING_KEY); } @end  

Announce a fixed variable so that you use its address Calling Objc_setAssociatedObject as the key key takes a zero * and only the address of your static variable is actually used, the content of NSString is not ... which is only wasting memory.

You just need to add:

Fixed four STRING_KEY; // global 0 initialization is ok, no // it is not necessary to change because / var is not a value, only the address

Comments