//Nsmutablearray inherit to Nsarray//Nsarray * array = @[]; //1. Creating a mutable arrayNsmutablearray * array = [[Nsmutablearray alloc] Initwithcapacity:0]; //adding elements to an array dynamically using AddObject /*[Array addobject:@ "one"]; [Array addobject:@ ""]; [Array addobject:@ "three"]; [Array addobject:@ "one"]; */NSString* STR1 =@" One"; NSString* STR2 =@" Both"; NSString* STR3 =@"three"; //The array can be stored in the same object multiple times[Array addobject:str1]; [Array addobject:str2]; [Array ADDOBJECT:STR3]; [Array addobject:str1]; //2. Specify where the object is inserted[Array insertobject:str1 Atindex:2]; //3. Delete objects that will delete all the same addresses in the array through the object[Array removeobject:str1]; //4. Deleting an object by index, exceeding the count value of the array, results in an exception of index beyond bounds[Array Removeobjectatindex:0]; [Array addobject:str2]; [Array ADDOBJECT:STR3]; [Array addobject:str1]; //5. Delete all elements in the array[Array removeallobjects]; NSLog (@"Array%@", array); [Array addobject:str2]; [Array ADDOBJECT:STR3]; [Array addobject:str1]; //1.for Swapping Traversal for(inti =0; i < Array.count; i++) {NSString* str =[Array objectatindex:i]; //do not add or remove elements to the array when iterating over the array.//[Array removeobject:str1];NSLog (@"Str%@", str); } //2. Enhanced for Loop for(NSString * STRinchArray) {//[Array removeobject:str1]; //If you delete an element in the enhanced for loop, it will directly cause an exception to appearNSLog (@"Str%@", str); } //3. EnumeratorsNsenumerator* Enumerator =[Array objectenumerator]; NSString*value; while(Value =[Enumerator Nextobject]) { //If you delete the element in the enumerator, it will directly cause the exception to appear//[Array removeobject:str1];NSLog (@"Str%@", value); } //4. How to determine which element to delete by traversingNsmutablearray* Array2 =[[Nsmutablearray alloc] init]; [Array2 AddObject:@"1"]; [Array2 AddObject:@"2"]; [Array2 AddObject:@"3"]; [Array2 AddObject:@"4"]; [Array2 AddObject:@"5"]; Nsmutablearray* TMP =[[Nsmutablearray alloc] init]; for(NSString * STRincharray2) { if([str isequaltostring:@"3"]) {[TMP addobject:str]; }} NSLog (@"array2%@", array2); NSLog (@"tmp%@", TMP); //iterating through a temporary array for(inti =0; i < Tmp.count; i++) {NSString* str =[tmp objectatindex:i]; //deleted from the original array, objects stored in the temporary array[Array2 Removeobject:str]; } NSLog (@"array2%@", array2);
Variable group Nsmutablearray