This is a new addition to Xcode 4.4+ and relies on the Apple LLVM + Clang compiler. This is a new feature: Arrays can also be accessed with the same notation: myObjectArray[4] .
If you are interested in adding this new function to your own classes (called subscriptip), you can implement several methods:
@interface NSArray(Subscripting) - (id)objectAtIndexedSubscript:(NSUInteger)index; @end @interface NSMutableArray(Subscripting) - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index; @end @interface NSDictionary(Subscripting) - (id)objectForKeyedSubscript:(id)key; @end @interface NSMutableDictionary(Subscripting) - (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; @end
If you implement any of these methods on your own classes, you can index them. Also you can add this feature in OS X 10.7 too!
source share