LoginSignup
16
16

More than 5 years have passed since last update.

NSArray, NSMutableArrayの高速列挙は順序を保証"する"

Last updated at Posted at 2012-12-26

保証しない、という情報をずっと信じていた恥ずかしい私をどうかお許しください。
今回のこの勘違いは、
ブログ等を安易に信じてはいけない、という教訓になりました。
昔のSDKのバグが原因なのか、一定量この情報が流れているきがします。

きちんと公式に書いてありました。信ずるべきは公式ドキュメントです。ブログではありませんね。
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html

  • (NSEnumerator *)objectEnumerator Return Value An enumerator object that lets you access each object in the array, in order, from the element at the lowest index upwards.

Discussion
Returns an enumerator object that lets you access each object in the array, in order, starting with the element at index 0, as in:

NSArray *array = <#Get an array#>;
NSUInteger index = 0;

for (id element in array) {
    NSLog(@"Element at index %u is: %@", index, element);
    index++;
}

なので安心して使いましょう。

16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16