 <p>The problem is that </p> <pre><code> objc_setAssociatedObject(self, &amp;imageNameKey, name, OBJC_ASSOCIATION_ASSIGN); </code></pre> <p>should be</p> <pre><code> objc_setAssociatedObject(self, &amp;imageNameKey, name, OBJC_ASSOCIATION_COPY_NONATOMIC); </code></pre> <p>or </p> <pre><code> objc_setAssociatedObject(self, &amp;imageNameKey, name, OBJC_ASSOCIATION_COPY); </code></pre> <p>Don't use <code>OBJC_ASSOCIATION_RETAIN</code> or <code>OBJC_ASSOCIATION_RETAIN_NONATOMIC</code> as the string might be mutable. Exactly the same reason the you declare string properties as copy rather than strong. </p> <p>When I test the below code the associated is set and retrieved correctly.</p> <pre><code>@implementation UIImage (Name) static char const imageNameKey; -(NSString *)getImageName { NSString* name = objc_getAssociatedObject(self, &amp;imageNameKey); return name; } -(void) setImageName:(NSString *)name { objc_setAssociatedObject(self, &amp;imageNameKey, name, OBJC_ASSOCIATION_COPY_NONATOMIC); } +(void)load { if(self == [UIImage class]) { Method originalImageNamed, swizzledImageNamed; originalImageNamed = class_getClassMethod(self, @selector(imageNamed:)); swizzledImageNamed = class_getClassMethod(self, @selector(swizzledImageNamed:)); method_exchangeImplementations(originalImageNamed, swizzledImageNamed); } } +(UIImage *)swizzledImageNamed:(NSString*) name { UIImage* image = [self swizzledImageNamed:name]; if(image) [image setImageName:name]; return image; } @end </code></pre>