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