Abdullah Shafique
Abdullah Shafique

Reputation: 6918

Create a tag for an NSString

I am trying to give a tag for an NSString by creating a category:

.h:

@property (nonatomic, copy) NSString *stringTag;

.m:

- (NSString *)stringTag
{
    return objc_getAssociatedObject(self, CFBridgingRetain(kStringTagKey));
}
- (void)setStringTag:(NSString *)stringTag
{
    objc_setAssociatedObject(self, CFBridgingRetain(kStringTagKey), stringTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

However I'm getting these errors:

enter image description here

Upvotes: 1

Views: 129

Answers (2)

Janak Nirmal
Janak Nirmal

Reputation: 22726

Please add an import statement as

#import <objc/runtime.h>

Upvotes: 6

godel9
godel9

Reputation: 7390

You need to add:

#import <objc/runtime.h>

Upvotes: 5

Related Questions