1 intMainintargcConst Char*argv[]) {2 @autoreleasepool {3 //an OC array can store objects of different types, and basic data types cannot be stored4 //The OC array stores pointers to objects5Nsarray *array = [[Nsarray alloc] Initwithobjects:@"1",@"2",@"3",@"4",@"5", nil];6 //the length of the array7 intCount = (int) Array.count;8NSLog (@"Count:%d", count);9 //determine if an object existsTenBOOL ishave = [Array containsobject:@"3"]; One if(ishave) { ANSLog (@"exist"); -}Else { -NSLog (@"does not exist"); the } - //output Last Object -NSString *str =[Array lastobject]; -NSLog (@"str =%@", str); + //output First Object -NSString *STR2 =[Array firstobject]; +NSLog (@"str2 =%@", str2); A //Remove the object that specifies the subscript in the array atstr = [Array Objectatindex:3]; -NSLog (@"str =%@", str); - //You can also return the location of the subscript by specific elements. - intindex = (int) [Array Indexofobject:@"1"]; -NSLog (@"index =%d", index);//If no element is specified, -1 is returned. - in //the traversal of the array (1. Basic for loop is removed by subscript check the 2.for in Fast enumeration 3. Enumerator (or iterator)) -People *p =[[People alloc] init]; toP.name =@"Zhang San"; +Nsarray *array2 = [[Nsarray alloc] Initwithobjects:@"a",@"b"P@"D",@"e", nil]; - //1. the for(inti =0; i<array.count; i++) { *NSString *STR1 =[Array2 objectatindex:i]; $NSLog (@"%@", str1);Panax Notoginseng } - //2. If you need to use fast enumeration, we need to keep the types of elements in the array consistent the for(NSString *stinchArray) { +NSLog (@"Duang:%@", ST); A } the //3. Slightly + } - return 0; $}
"Mu-Guest Network: basic framework for iOS Basics" Learning notes < three > Nsarray