public
Created

  • Download Gist
banana_array.m
Objective-C
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 BananaBox : NSObject
- (id)objectAtIndexedSubscript:(NSUInteger)idx;
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
@end
 
@implementation AppleCart
NSMutableArray *_bananas;
 
-(id) init {
self = [self init]
if (self} {
_bananas = [[NSMutableArray alloc] init];
}
return self;
}
 
- (id)objectAtIndexedSubscript:(NSUInteger)idx {
return _bananas[idx];
}
 
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx {
_bananas[idx] = obj;
}
@end
 
BananaBox *bananaBox = [[BananaBox alloc] init];
bananaBox[0] = @"Delicious banana";
bananBox[0]; // Returns "Delicious banana"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.