Objective-C 中的快速枚举能保证迭代的顺序吗?

Does fast enumeration in Objective-C guarantee the order of iteration?(Objective-C 中的快速枚举能保证迭代的顺序吗?)
本文介绍了Objective-C 中的快速枚举能保证迭代的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can I expect it to go from the start of an array to the end in order? Can't find anything in the docs about this.

即是

for (id val in array)
{
   NSLog(@"%@", val);
}

总是会打印出相同的结果

always going to print out the same as

for (int i = 0; i < [array count]; ++i)
{
   NSLog(@"%@", [array objectAtIndex:i]);
}

推荐答案

来自 Apple 的 Objective-C 文档 关于快速枚举:

From Apples' Objective-C documentation on fast enumeration:

对于具有明确定义顺序的集合或枚举器(例如从数组派生的 NSArray 或 NSEnumerator 实例),枚举按该顺序进行,因此如果需要,只需计算迭代次数即可为您提供正确的集合索引.

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 中的快速枚举能保证迭代的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)