objective-c - Objective-C 中的快速枚举是否保证迭代顺序?

标签 objective-c arrays iteration fast-enumeration

我可以期望它按顺序从数组的开头到结尾吗?在文档中找不到任何关于此的内容。

即是

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/

相关文章:

ios - 用户界面没有更新,而某些功能需要时间才能执行?

objective-c - 如何创建一个 4 字节大的 NSData?

recursion - 从递归到迭代的方法

Java——迭代不起作用

jquery:使用上下键迭代列表项 ->光标位置?

ios - 如何正确检测设备 objective-c 的语言用户?

objective-c - 在 C 中的结构中扩展数组

arrays - MATLAB:从结构数组中收集

javascript - 使用 Angular ng-repeat 获取数组的最后一个索引

java - 打印空数组