1#pragmaMark---------------Variable Array-----------------
2//can be used in the array to delete and modify the operation
3//
4//variable arrays are related to arrays: mutable arrays are subclasses of arrays,
5//How to initialize a mutable array
6//Nsmutablearray *array= [[Nsmutablearray alloc] init];
7 //Nsmutablearray *array1 = [Nsmutablearray array];
8//Nsmutablearray *array2 = [Nsmutablearray arraywithobject:@ ""];
9//Nsmutablearray *array3 = [Nsmutablearray arraywithobjects:@ "", @ "", nil];
Ten//Nsmutablearray *array4 = @[@ ""]; you can't write this, remember, this is a difference between a mutable array and an array so that the elements inside it are immutable.
One//variable arrays can add elements to an array
A//Be sure to initialize when using a mutable array
-Nsmutablearray *array = [Nsmutablearray array];
-//Adding a method to a mutable array
the//[Array addobject:@ "Huluwan"];
-//[Array addobject:@ "Aoteman"];
-//NSLog (@ "%@", array);
-
+ //1. The number of 1~100 stored in the array
-//arrays are initialized outside of the loop, otherwise each loop is instantiated with an array
+//for (int i = 0; i <; i + +) {
A ////NSNumber *num = [NSNumber numberwithint:i];
at////[Array addobject:num];
-//[Array addobject:@ (i)];
-// }
-//NSLog (@ "shu:%@", array);
-
- //Monkey King every time learning a new skill called skill 1 ..... 72
in//nsstring *jineng = @ "Skill";
- for(inti =1; I < the; i + +) {
to//nsnumber *num = [NSNumber numberwithint:i];
+ //[Array addobject:num];
-NSString *skillname = [NSString stringWithFormat:@"Skill%d", I];
the
*[Array addobject:skillname];
$}
Panax Notoginseng for(inti =0; I < the; i + +) {
-NSLog (@"shu:%@", Array[i]);
the}
+//NSLog (@ "shu:%@", array);
A[Array Removeobjectatindex: -];
the//[Array removeallobjects];
+ [Array Removeobject:@"Skill 7"];//Remove "Skill 7"
-
$//for (int i = 0; i <; i + +) {
$ //NSLog (@ "shu:%@", Array[i]);
-// }
-//NSLog (@ "shu:%@", array);
the
-Nsmutablearray *group = [Nsmutablearray array];
Wuyi for(inti =0; I <5; i + +) {
the[Group Addobject:[nsstring stringWithFormat:@"classmate%d". II1]];
-
Wu}
-//each element inside the ID obj array
About//in which inside
$//array to be traversed by group
-//The same functionality as the For loop above
- for(IDObjinchGroup) {
-NSLog (@"%@", obj);
A}
+
the//[group Firstobject];//get the first element of an array
-//[group Lastobject];//get the last element of the array
$[Group Removeobjectatindex:3];//Removing an element with a corner mark of 3
the[Group Replaceobjectatindex:3Withobject:@"fengshenghai666"];//Replace the third element with a fengshenghai666
theNSLog (@"%@", group);
Execution Result:
Objective-c variable Array