Skip to content

Instantly share code, notes, and snippets.

@mjjimenez
Created December 14, 2013 06:57
Show Gist options
  • Save mjjimenez/7956352 to your computer and use it in GitHub Desktop.
Save mjjimenez/7956352 to your computer and use it in GitHub Desktop.
Add string type tag to UIViews
#import <UIKit/UIKit.h>
@interface UIView (StringTagAdditions)
@property (nonatomic, copy) NSString *stringTag;
@end
#import "UIView+StringTagAdditions.h"
#import <objc/runtime.h>
@implementation UIView (StringTagAdditions)
static NSString *kStringTagKey = @"StringTagKey";
- (NSString *)stringTag
{
return (NSString*) objc_getAssociatedObject(self, CFBridgingRetain(kStringTagKey));
}
- (void)setStringTag:(NSString *)stringTag
{
objc_setAssociatedObject(self, CFBridgingRetain(kStringTagKey), stringTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment