[Nsarray] A definition of 1 immutable array of 2 OC elements can be any object 3 number containing the address of the element in the second initialization nsarray * variable = [[Nsarry alloc] initwithobjects: Object ..., nil] ; Three usage scenarios 1 times the group A enumeration Nsenumerator *enums = [Array1 objectenumerator]; while (Obj=[enums Nextobject]) B subscript for (i=0;i<count;i++) {C Fast enumeration method for (ID obj in array1) 2 gets the length int count = [Array Object count];[ Nsmutablearray] A definition of 1 variable array 2 can be inserted any object two initialization nsmutablearray * variable name = [[Nsmutablearray alloc] init]; three use scene 1 Add object [Mutablearray AddO bject:@ "JACK"];2 replace Object [Mutablearray exchangeobjectatindex:0 withobjectatindex:2];3 Remove Object [Mutablearray removeObject: Person]; [Mutablearray Removeobjectatindex:0];4 Sequential enumeration traversal nsenumerator *_enums = [Mutablearray OBJECTENUMERATOR];5 Reverse enumeration traversal nsenumerator *_reverseenums = [Mutablearray reverseobjectenumerator];6 string and array conversions Nsarray *_strarray = [str componentsseparatedbystring:@ "]; NSString *str = [_strmutablearray componentsjoinedbystring:@ ""];
////main.m//oc-Array////Created by Wangtouwang on 15/3/20.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import<Foundation/Foundation.h>#import "Person.h"intMainintargcConst Char*argv[]) {@autoreleasepool {//non-variable group NsarryNSLog (@"Nsarry"); person*person = [PersonNew]; Person._name=@"JACK"; //InitializeNsarray *array1 = [[Nsarray alloc] Initwithobjects:@"Jack",@"Lucy", person, nil]; NSLog (@"%@", array1); //EnumerationNSLog (@"The enumerator method prints the array result:"); Nsenumerator*enums =[Array1 Objectenumerator]; IDobj; while(obj=[enums Nextobject]) {NSLog (@"%@", obj); } //Quick EnumerationNSLog (@"Fast Enumeration method for printing array results:"); for(IDObjincharray1) {NSLog (@"%@", obj); } //Subscript ConvenienceNsinteger i =2; IDObj2 =[Array1 objectatindex:i]; NSLog (@"%@", OBJ2); //Get lengthNsinteger count=[array1 Count]; NSLog (@"Array length%lu", Count); I=0; for(i=0; i<count;i++) {NSLog (@"%@", [array1 objectatindex:i]); } //variable array NsmutablearrayNsmutablearray*mutablearray =[[Nsmutablearray alloc] init]; //Increase[Mutablearray AddObject:@"JACK"]; [Mutablearray AddObject:@"MOBILE"]; [Mutablearray AddObject:@"TEL"]; [Mutablearray AddObject:@" Book"]; [Mutablearray AddObject:@"STUDENT"]; [Mutablearray Addobject:person]; NSLog (@"%@", Mutablearray); //Replace ObjectNSLog (@"Replace Object"); [Mutablearray Exchangeobjectatindex:0Withobjectatindex:2]; NSLog (@"%@", Mutablearray); //removing object parameter ID typesNSLog (@"removing object parameter ID types"); [Mutablearray Removeobject:person]; NSLog (@"%@", Mutablearray); //Remove Object parameter NsintegerNSLog (@"Remove Object parameter Nsinteger"); [Mutablearray Removeobjectatindex:0]; NSLog (@"%@", Mutablearray); //Positive-Order enumeration traversalNSLog (@"Positive-Order enumeration traversal"); Nsenumerator*_enums =[Mutablearray Objectenumerator]; IDobj3; while(obj3=[_enums Nextobject]) {NSLog (@"%@", OBJ3); } //Reverse enumeration traversal and can be deleted over timeNSLog (@"Reverse enumeration traversal and can be deleted over time"); Nsenumerator*_reverseenums =[Mutablearray Reverseobjectenumerator]; while(obj3=[_reverseenums Nextobject]) {NSLog (@"%@", OBJ3); [Mutablearray REMOVEOBJECT:OBJ3]; } NSLog (@"Reverse enumeration Traversal end View Array length%lu", [Mutablearray Count]); //conversion of strings and arraysNSString *str =@"Hello World Hao is you"; Nsarray*_strarray = [str componentsseparatedbystring:@" "]; NSLog (@"lenght =%lu", [_strarray Count]); Nsmutablearray*_strmutablearray =[[Nsmutablearray alloc] init]; Nsenumerator*_strenums =[_strarray Reverseobjectenumerator]; NSString*objstring; while(objstring=[_strenums Nextobject]) {[_strmutablearray addobject:objstring]; } NSLog (@"%@", _strmutablearray); STR= [_strmutablearray componentsjoinedbystring:@" "]; NSLog (@"%@", str); } return 0;}
IOS Learning Note 2015-03-20 oc-array