Last Updated: February 25, 2016
·
1.401K
· jeremytregunna

Array subscripting in Objective-C

If you're not using the iOS 6 SDK, adding this bit of code to your projects precompiled header will allow you on Xcode 4.4 to use array subscripting. It's also perfectly compatible with iOS 6's SDK.

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
@interface NSObject (ArraySubscriptingSupport)
- (id)objectAtIndexedSubscript:(NSUInteger)idx;
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
- (id)objectForKeyedSubscript:(id)key;
@end
#endif