各类遍历写法的比较

连接:http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html
html

NSArray:ios

  • for (id object in array) :正向遍历最快;
  • for (id object in [array reverseObjectEnumerator]) : 反向遍历;
  • for (NSInteger i = 0; i < count; i++) : 当须要使用index或修改内容,先算出Count,再遍历最快;
  • [array enumerateObjectsWithOptions:usingBlock:]: 须要并行遍历时;

NSSet:objective-c

  • for (id object in set):遍历最快;
  • for (id object in [set copy]):须要修改内容时;
  • [set enumerateObjectsWithOptions:usingBlock:] 须要并行遍历时.

NSDictionary:oop

  • [dictionary enumerateKeysAndObjectsUsingBlock:] :遍历最快;
  • for (id key in [dictionary allKeys]): 须要修改内容时;
  • [dictionary enumerateKeysAndObjectWithOptions:usingBlock:]: 须要并行遍历时.
相关文章
相关标签/搜索