4 ms·
You can use them on iOS 5.1 by implementing the methods the subscripts map to on NSArray and NSDictionary (as well as mutable) in categories. For NSArray:
by weiran 14y ago
You can use them on iOS 5.1 by implementing the methods the subscripts map to on NSArray and NSDictionary (as well as mutable) in categories.
For NSArray:
- (id)objectAtIndexedSubscript:(NSUInteger)index {
return [self objectAtIndex:index];
}
NSMutableArray:
- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index {
if (index < self.count){
if (object)
[self replaceObjectAtIndex:index withObject:object];
else
[self removeObjectAtIndex:index];
} else {
[self addObject:object];
}
}
NSDictionary:
- (id)objectForKeyedSubscript:(id)key {
return [self objectForKey:key];
}
NSMutableDictionary:
- (void)setObject:(id)object forKeyedSubscript:(id)key {
[self setObject:object forKey:key];
}
- michaelmior 14y agoIs it just as easy as creating categories that add these methods?
- puls 14y agoThe implementation already exists in iOS 5, you just need to make the compiler happy; a header that declares them is sufficient.