Objective-c variable Array

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.