Syntax used for quick enumeration:
For (type newvariable in expression) {statements}
Or
Type existingitem;
For (existingitem in expression) {statements}
Objects cannot be changed during enumeration.
Use the following three classes for quick enumeration:
Nsarray, nsdictionary, nsset
How to use:
Nsarray * array = [nsarray arraywithobjects:
@ "One", @ "two", @ "three", @ "four", nil];
For (nsstring * element in array ){
Nslog (@ "element: % @", element );
}
Nsdictionary * dictionary = [nsdictionary dictionarywithobjectsandkeys:
@ "Quattuor", @ "four", @ "quinque", @ "five", @ "sex", @ "six", nil];
Nsstring * key;
For (key in dictionary ){
Nslog (@ "English: % @, Latin: % @", key, [dictionary objectforkey: Key]);
}
You can also use enumeration:
Nsarray * array = [nsarray arraywithobjects:
@ "One", @ "two", @ "three", @ "four", nil];
Nsenumerator * enumerator = [array reverseobjectenumerator];
For (nsstring * element in enumerator ){
If ([element isinclutostring: @ "three"]) {
Break;
}
}
Nsstring * Next = [enumerator nextobject];
// Next = "two"