Forked from kostiakoval/Associated-NSNumber.codesnippet
Created
July 3, 2014 14:45
-
-
Save pwblaine/074eee3e8ccfd5b93e09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| - (<#type#>)<#propertyName#> { | |
| return [objc_getAssociatedObject(self, _cmd) <#NSNumberMethod#>]; | |
| } | |
| - (void)set<#propertyName#>:(<#type#>)object | |
| { | |
| objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_); | |
| } |
This file contains hidden or 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
| - (<#type#>)<#propertyName#> { | |
| return objc_getAssociatedObject(self, _cmd); | |
| } | |
| - (void)set<#propertyName#>:(<#type#>)object | |
| { | |
| objc_setAssociatedObject(self, @selector(<#propertyName#>), object, OBJC_ASSOCIATION_); | |
| } |
This file contains hidden or 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
| // | |
| // NSObject+Assosiated.h | |
| // NSObject-Associated | |
| // | |
| // Created by Konstantin Koval on 29/03/14. | |
| // Copyright (c) 2014 Konstantin Koval. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSObject (AssociatedTest) | |
| @property (nonatomic, strong) NSString *name; | |
| @property (nonatomic, assign) id delegate; | |
| @end | |
| // Implementation | |
| #import "KKNSObject+Associated.h" | |
| @implementation NSObject (AssociatedTest) | |
| ASSOCIATED(name, setName, NSString *, OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
| ASSOCIATED(delegate, setDelegate, id, OBJC_ASSOCIATION_ASSIGN) | |
| @end |
This file contains hidden or 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
| // | |
| // KKNSObject+Assosiated.h | |
| // NSObject-Associated | |
| // | |
| // Created by Konstantin Koval on 29/03/14. | |
| // Copyright (c) 2014 Konstantin Koval. All rights reserved. | |
| // | |
| /** | |
| * A macro that creates getter and setter for your assosiated object | |
| * | |
| * @param propertyName Getter funtion name | |
| * @param setter Setter funtion name | |
| * @param objc_AssociationPolicy Memory policy for assosiated object | |
| * | |
| * Available option: OBJC_ASSOCIATION_ASSIGN, OBJC_ASSOCIATION_RETAIN_NONATOMIC, OBJC_ASSOCIATION_COPY_NONATOMIC, OBJC_ASSOCIATION_RETAIN, OBJC_ASSOCIATION_COPY | |
| * | |
| */ | |
| #import <objc/runtime.h> | |
| #define ASSOCIATED(propertyName, setter, type, objc_AssociationPolicy)\ | |
| - (type)propertyName {\ | |
| return objc_getAssociatedObject(self, _cmd);\ | |
| }\ | |
| \ | |
| - (void)setter:(type)object\ | |
| {\ | |
| objc_setAssociatedObject(self, @selector(propertyName), object, objc_AssociationPolicy);\ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment