Created
February 12, 2012 21:09
-
-
Save hamrickdavid/1810860 to your computer and use it in GitHub Desktop.
Adding Properties to an Objective-C Category
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 UIViewDHStyleManager.h" | |
UIView* v = [[[UIView alloc] init] autorelease]; | |
v.styleName = @"someStyleName"; | |
NSLog(@"v = %@",v.styleName); //Logs 'someStyleName' |
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
@interface UIView (DHStyleManager) | |
@property (nonatomic, copy) NSString* styleName; | |
@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 "UIViewDHStyleManager.h" | |
NSString * const kDHStyleKey = @"kDHStyleKey"; | |
@implementation UIView (DHStyleManager) | |
- (void)setStyleName:(NSString *)styleName | |
{ | |
objc_setAssociatedObject(self, kDHStyleKey, styleName, OBJC_ASSOCIATION_COPY); | |
} | |
- (NSString*)styleName | |
{ | |
return objc_getAssociatedObject(self, kDHStyleKey); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment