对于...声明Objective-C [英] For...in statement Objective-C
本文介绍了对于...声明Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究Objective-C,并且遇到了这个"for ... in"声明.我搜索了它,但仍然不知道它是如何工作的.有人可以以友好的方式向我解释此声明的工作原理吗?
I am studying Objective-C and I came across this "for...in" statement. I searched for it but i still don't get how it works. Could someone explain to me in a noob-friendly how this statement works?
推荐答案
Basically you'd have, usually, an array, and you can obtain each item in the array with a handy loop instead of using NSEnumerator or an integer count variable. It makes your code much cleaner to ask for each NSString in your array rather than to have to assign to a variable using objectAtIndex
for each pass of your loop.
比较:
for (NSString *string in myArray)
{
// do stuff...
}
收件人:
for (int i = 0; i < [myArray count]; i++)
{
NSString *string = [myArray objectAtIndex:i];
// Do stuff...
}
这篇关于对于...声明Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文