Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View banana_dictionary.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
@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
Something went wrong with that request. Please try again.