Created
September 21, 2012 14:33
-
-
Save thechrisoshow/3761805 to your computer and use it in GitHub Desktop.
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 Banana : NSObject | |
- (id)objectForKeyedSubscript:(id)key; | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; | |
@end | |
@implementation Banana | |
NSMutableDictionary *_attributes; | |
-(id) init { | |
self = [self init]; | |
if (self) { | |
_attributes = [[NSMutableDictionary alloc] init]; | |
} | |
return self | |
} | |
- (id)objectForKeyedSubscript:(id)key { | |
return _attributes[key]; | |
} | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key { | |
_attributes[key] = obj; | |
} | |
@end | |
Banana *banana = [[Banana alloc] init]; | |
banana[@"colour"] = @"Yellow"; | |
banana[@"colour"]; // returns "Yellow" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment