Created
September 11, 2011 18:10
-
-
Save epatel/1209914 to your computer and use it in GitHub Desktop.
Adding AssociatedObject to NSObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSObject (AssociatedObject) | |
- (id)associatedObjectForKey:(void*)key; | |
- (void)setAssociatedObject:(id)object forKey:(void*)key; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSObject+AssociatedObject.h" | |
#import <objc/runtime.h> | |
@implementation NSObject (AssociatedObject) | |
- (id)associatedObjectForKey:(void*)key | |
{ | |
return objc_getAssociatedObject(self, key); | |
} | |
- (void)setAssociatedObject:(id)obj forKey:(void*)key | |
{ | |
objc_setAssociatedObject(self, key, obj, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment