链接:
NSArray:
- for (id object in array) :正向遍历最快;
- for (id object in [array reverseObjectEnumerator]) : 反向遍历;
- for (NSInteger i = 0; i < count; i++) : 当需要使用index或修改内容,先算出Count,再遍历最快;
- [array enumerateObjectsWithOptions:usingBlock:]: 需要并行遍历时;
NSSet:
- for (id object in set):遍历最快;
- for (id object in [set copy]):需要修改内容时;
- [set enumerateObjectsWithOptions:usingBlock:] 需要并行遍历时.
NSDictionary:
- [dictionary enumerateKeysAndObjectsUsingBlock:] :遍历最快;
- for (id key in [dictionary allKeys]): 需要修改内容时;
- [dictionary enumerateKeysAndObjectWithOptions:usingBlock:]: 需要并行遍历时.