开发者

Sort/Enumerate an NSArray from somewhere in the middle?

I have an NSArray, with objects ordered like so:

  • a
  • b
  • c
  • d
  • e
  • f

I would like to enumerate through this array in this order:

  • c
  • d
  • e
  • f
  • a
  • b

i.e. starting at some point that is not the beginning, but hitting all the items.

I imagine this is a matter of sorting first and then enumerating the array, but I'm not sure if that's the best technique... or, frankly, how to sort the array like this.

Edit

Adding details: These will be relatively small arrays, varying from 3 to 10 objects. No concurrent access. I'd like to permanently alter 开发者_高级运维the sort order of the array each time I do this operation.


NSUInteger n = arr.count;
for (NSUInteger i = 0; i < n; ++i) {
    id e = [arr objectAtIndex:(start + i)%n];
    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜