Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Last active August 15, 2018 22:01
Show Gist options
  • Save serhatsezer/dca59ba6bcafa7877950aeb518f8c135 to your computer and use it in GitHub Desktop.
Save serhatsezer/dca59ba6bcafa7877950aeb518f8c135 to your computer and use it in GitHub Desktop.
@interface UIImage (Caption)
@property (nonatomic, copy) NSString *caption;
@end
// Implementation
#import <objc/runtime.h>
static const void *ImageCaptionKey = &ImageCaptionKey;
@implementation UIImage (Caption)
- (void)setCaption:(NSSting *)caption {
objc_setAssociatedObject(self, ImageCaptionKey, caption, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSString *)caption {
return objc_getAssociatedObject(self, ImageCaptionKey);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment