Does fast enumeration in Objective-C guarantee the order of iteration?(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 中的快速枚举能保证迭代的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Objective-C 中的快速枚举能保证迭代的顺序吗?


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01