我可以期望它按顺序从数组的开头到结尾吗?在文档中找不到任何关于此的内容。
即是
for (id val in array)
{
NSLog(@"%@", val);
}
总是会打印出同样的结果
for (int i = 0; i < [array count]; ++i)
{
NSLog(@"%@", [array objectAtIndex:i]);
}
最佳答案
来自苹果的 Objective-C documentation关于快速枚举:
For collections or enumerators that have a well-defined order—such as NSArray or NSEnumerator instance derived from an array—the enumeration proceeds in that order, so simply counting iterations will give you the proper index into the collection if you need it.
关于objective-c - Objective-C 中的快速枚举是否保证迭代顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2777607/