什么是更快?枚举VS For循环

编程入门 行业动态 更新时间:2024-10-07 12:23:01
本文介绍了什么是更快?枚举VS For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目标C和iphone的速度更快?自我枚举或for循环?

What is faster in objective C and iphone? self enumeration or for loop?

我有两个代码片段,可以帮助我比较。

i have 2 fragments of code to help me compare.

我们有一个事实,数组是一个NSMutableArray与x项目。 案例1:

for this example we have as a fact that array is an NSMutableArray with "x" items. Case 1:

-(void)findItem:(Item*)item { Item *temp; for (int i = 0 ;i<[array count];i++) { temp = [array objectAtIndex:i]; if(item.tag == temp.tag) return; } }

案例2:

-(void)findItem:(Item*)item { for(Item *temp in array) { if(item.tag == temp.tag) return; } }

很明显case2更快, ?

it is almost obvious that case2 is faster, is it?

推荐答案

这称为快速枚举。

请参阅: cocoawithlove/2008/05/fast-enumeration-clarifications.html

更多推荐

什么是更快?枚举VS For循环

本文发布于:2023-11-29 15:42:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更快

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!