I noticed that both array[index] and [array objectAtIndex:index] work with mutable arrays. Could someone explain the difference between them? in terms of performance, and which one is the best practice?
Whats the difference between array[index] and [array objectAtIndex:index]?
1.3k Views Asked by Hamad AlGhanim At
3
There are 3 best solutions below
1
On
Prior to Xcode 4.4, objectAtIndex: was the standard way to access array elements. Now it can be accessed through the square-bracket subscripting syntax aswell.
0
On
Technically, the array[index] syntax resolves into a call of the -objectAtIndexedSubscript: method on the array. For NSArray, this is documented as being identical to -objectAtIndex:.
The subscripting mechanism can be extended to other classes (including your own). In theory, such a class could do something different for -objectAtIndexedSubscript: than for -objectAtIndex:, but that would be poor design.
None. That's part of the clang extensions for objective-c literals, added 2-3 years ago.
Also: