码迷,mamicode.com
首页 > 其他好文 > 详细

遍历collection

时间:2016-09-10 17:54:11      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

[链接](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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!