[链接](http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html)
##遍历NSArray
- 正向遍历
```
for (id object in array)
```
- 反向遍历
```
for (id object in [array reverseObjectEnumerator])
```
- 如果在遍历中修改
先计算出array的count,然后使用for循环。在for循环中记录需要修改的index,然后修改。
```
NSUInteger count = [array count];
for (NSUInteger i = 0; i < count; i++)
{
id object = array[i];
…
}
```
- 使用多线程
如果对元素的每一个操作比较耗时,那么利用并行操作会节省时间。
##遍历NSSet
- 多数时间使用` for (id object in set)`
- 如果想修改,使用`(id object in [set copy])`
- 如果想利用并行性,使用` [set enumerateObjectsWithOptions:usingBlock:] `
##遍历NSDictionary
- 多数时间使用` [dictionary enumerateKeysAndObjectsUsingBlock:] `
- 如果需要修改,使用` for (id key in [dictionary allKeys]) `
- 如果想利用并行性,使用`[dictionary enumerateKeysAndObjectWithOptions:usingBlock:] `遍历collection
原文:http://www.cnblogs.com/huahuahu/p/bian-licollection.html