Does fast enumeration in Objective-C guarantee the order of iteration?

前端 未结 2 842
忘掉有多难
忘掉有多难 2020-12-15 15:53

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.

i.e. is

for (id val in array)
{
           


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 16:37

    From Apples' Objective-C documentation on fast enumeration:

    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.

提交回复
热议问题