Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Created March 13, 2017 08:05
Show Gist options
  • Save joanmolinas/ec8690f5fc08b375e60ff3d705f207ef to your computer and use it in GitHub Desktop.
Save joanmolinas/ec8690f5fc08b375e60ff3d705f207ef to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface NSObject (AssociatedObjects)
- (void)associatedValue:(id)value withKey:(void *)key;
- (id)associatedValueForKey:(void *)key;
@en
#import "NSObject+AssociatedObjects.h"
#import <objc/runtime.h>
@implementation NSObject (AssociatedObjects)
- (void)associatedValue:(id)value withKey:(void *)key {
objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_RETAIN);
}
- (id)associatedValueForKey:(void *)key {
return objc_getAssociatedObject(self, key);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment