Because of cocoa design patterns, the name of the instance method count
in NSMutableArray
is ambiguous; it could either return a saved variable
As you have correctly noted, there is no guarantee that it will behave one way or the other.
In practice, though, -[NSArray count]
is a constant-time operation. You can confirm this yourself by creating a small array and a large array and benchmarking the time it takes to get their counts. It would be pretty silly to have an O(n) count
method on the core array classes like this.