//1. Iterating through an array with A for loopNsarray * array = @[@" One",@" Both",@"three"]; for(inti =0; i < Array.count; i++) {NSString* str =Array[i]; NSLog (@"array[%d] =%@", I,STR); } //1. Data type//BOOL ID nsobject * (nsstring * nsarray *) block SEL//2. Process Control Statements//Enhanced for Loop /*For (NSObject * obj in array) {}*/ //What is the value of your array.count, how many times he loops, and every time you take out an element in the data//stored in STR//2. Iterating through an array using the enhanced for loop method for(NSString * STRinchArray) {NSLog (@"str =%@", str); } //3. Precautions//If you have a variety of different types of data in your array, it's best not to invoke an object-specific method that will cause the program to crash//in real-world development, an array is often responsible for storing only one type of dataPerson * P1 =[[Person alloc] init]; Nsarray* Array2 = @[@" One", [NSNumber Numberwithint:Ten],P1]; for(NSString * STRincharray2) {//NSLog (@ "array2 str%@", str);//NSLog (@ "str%ld", str.length); } //3. EnumeratorsNsarray * Array3 = @[@" One",@" Both",@"three"]; Nsenumerator* Enumerateor =[Array3 Objectenumerator]; NSString*value; while(Value =[Enumerateor Nextobject]) {NSLog (@"enum STR%@", value); }
Traversal of an array