Is there an easy way to iterate over an NSArray backwards?

前端 未结 5 1650
半阙折子戏
半阙折子戏 2020-12-29 01:57

I\'ve got an NSArray and have to iterate over it in a special case backwards, so that I first look at the last element. It\'s for performance reasons: If the la

5条回答
  •  情话喂你
    2020-12-29 02:33

    From here:

     NSEnumerator* myIterator = [myArray reverseObjectEnumerator];
     id anObject;
    
     while( anObject = [myIterator nextObject])
     {
         /* do something useful with anObject */
     }
    

提交回复
热议问题