For arrays, dictionaries, and collections, objective-C provides an enumeration method to access each element. There are two methods:
Method 1:
Nsarray * array = ...; member * member; int COUNT = [array count]; for (INT I = 0; I <count; I ++) {member = [array objectatindex: I]; nslog ([member description]);}
Method 2:
For (member * membre in array) {nslog ([member description]);}
Array example:
For (student * stu4 in students) {nslog (@ "Name: % @, age: % I", stu4.name, stu4.age );}
Set example:
For (nsnumber * interger in self) {printf ("% Li", [interger intergervalue]);}
Dictionary example:
Nsmutabledictionary * employes = [nsmutabledictionary dictionary]; [employes setobject: @ "Zhang San" forkey: @ "1"]; // Add a key-value [employes setobject: @ "" forkey: @ "2"]; // Add a key-value [employes setobject: @ "" forkey: @ "3"]; // Add a key-value for (nsstring * key in employes) {nslog (@ "% @, % @", key, [employes objectforkey: Key]);}