I keep forgetting where this link is, so I’m putting it here: CLang Reference: Objective C, Object Subscripting.
This documents the methods we need to define if we are declaring our own Objective C class and we want to implement array-style subscripting or dictionary-style subscripting.
Extracting from the text:
… Moreover, because the method names are selected by the type of the subscript, an object can be subscripted using both array and dictionary styles.
Meaning if the compiler detects the subscript is an integral type, it uses the array-style subscript method calls, and when the subscript is an Objective C pointer type, it uses a dictionary-style subscript method call.
For array subscripting, use either or both of the methods
- (id<NSObject>)objectAtIndexedSubscript:(NSInteger)index; - (void)setObject:(id<NSObject>)value atIndexedSubscript:(NSInteger)index;
For dictionary-style subscripting, use either or both of the methods
- (id<NSObject>)objectForKeyedSubscript:(id<NSObject>)key; - (void)setObject:(id<NSObject>)value forKeyedSubscript:(id<NSObject>)key;
This goes hand-in-hand with my earlier post Objective C declaration shortcuts, and has been a public service announcement.