Objective-c Array

Source: Internet
Author: User

1#pragmaMark-----------How arrays are initialized--------------
2//Insert code here ...
3//NSLog (@ "Hello, world!");
4//How arrays are initialized
5//1. Initializing an empty array
6//Nsarray *array = [[Nsarray alloc] init];//immutable arrays, which cannot be added, deleted, replaced, etc. elements within an array
7//2. Initializing an empty array
8//Nsarray *array = [Nsarray array];
9//3. Initialize an array and assign a value to the array
Ten//Nsarray *array = [Nsarray arraywithobject:@ ""];//you can put any type of data in the array.
One//4. Initialize the students to add multiple elements
A//Nsarray *array = [Nsarray arraywithobjects:@ "", @ "", nil];//Be careful not to forget to write nil, there is a comma in front of it,
-//5. New ways to write arrays
-//Nsarray *array = @[@ "", @ ""];
theNsarray *list = [Nsarray arraywithobjects:@"Lu BU",@"Little Joe .",@"Big Joe",@"Guan Yu",@"Cao Zhi", nil];
- //array values, by the array subscript value, subscript starting from 0, the method of the element inside the array Objectatindex
-[List Objectatindex:0];
-//New Method
+//What type of variable will be used to receive the array?
-//nsstring *name = list[1];
+NSLog (@"%@", list[2]);
A
at
-Nsarray *fujingderen = [Nsarray arraywithobjects:@"Luo's cloud floating",@"Li Yongjun",@"Feng Shenhai",@"Liu Chunlin",@"Liu Shuishi",@"Ying Ying",@"Huang Junfan", list, nil];
-Nsarray *pangbianderen = @[@"Luo's cloud floating",@"Li Yongjun",@"Feng Shenhai",@"Liu Chunlin",@"Liu Shuishi",@"Ying Ying",@"Huang Junfan",@"Rongwei",@""];
-//for (int i = 0; i < 6; i + +) {
-//NSLog (@ "People nearby are:%@", [Fujingderen objectatindex:i]);
-//NSLog (@ "next to the person is:%@", Pangbianderen[i]);
in//        }
-//The values of the arrays in the array
to Nsarray *list1 =[nsarray Arraywithobjects:list,fujingderen,pangbianderen, nil];
+//The values of the arrays in the array
-NSLog (@"the arrays in the array are:%@", list1[1][7][0]);
the
*//Nsarray *herolist = @[@ "Galen", @ "Easy", @ "Kinks", @ "Germany State", @ "mention Mo", @ "Ya", @ "Morgana", @ "Raven", @ "female police", @ "Rui", @ "widow", @ "small cannon", @ "brilliant"];
$//for (int i = 0; i <; i + +) {
Panax Notoginseng//NSLog (@ "Input number%d select hero:%@", I, herolist[i]);
-//        }
the//int num;
+ //scanf ("%d", &num);
A//NSLog (@ "The hero you choose is:%@", Herolist[num]);
the#pragmaMark------------Conversion of data types---------------
+//what is required in the array is the type of the ID required to convert the base data type to the NSNumber type
-intAge = -;
$ints =1;
$NSLog (@"%012d", s);
-NSNumber *agenum = [[NSNumber alloc] initwithint:age];
-NSLog (@"%@", Agenum);
theNSNumber *agenum1 = [NSNumber numberwithint:age];
-NSLog (@"%@", AGENUM1);
WuyifloatXiaoshu =123.12343;
the//NSLog (@ "%.5f", Xiaoshu);
-NSNumber *xiaoshu = [NSNumber Numberwithfloat:xiaoshu];
WuNSLog (@"%@", Xiaoshu);
-//ignore any type, @ (the type that needs to be converted). It is converted to NSNumber type
AboutNSNumber *newxiaoshu = @ (Xiaoshu);
$NSLog (@"%@", Newxiaoshu);
-//now convert the NSNumber type to float type
-floatAA = [Newxiaoshu floatvalue];
-NSLog (@"%.5f", AA);
A
+//write an array of fractions, and take the values in the array and turn them into the float type .
the floatShuxue =89.5;
-floatYuwen = -;
$floatYingyu =70.7;
theNSNumber *ss = @[@ ( at)];
the
the
theNsarray *score = @[@ (Shuxue), @ (Yuwen), @ (Yingyu)];
-NSLog (@"%@", score);

Execution Result:

Objective-c 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.