------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------
/*
Basic introduction of 1.NSAarrray
1) What is Nsarray
C language array: An ordered set of elements of the same type (ordered exponential group subscript and memory address ordered, not referring to content)
Nsarray is an array class in OC, and in development try to use Nsarray instead of array in C language
The drawbacks of arrays in C language
int array[4] = {10,43,252,24};
Only one type of data can be stored (the type must be the same)
Unable to easily add and remove array elements dynamically (fixed length)
2) attention to the use of Nsarray
Only OC objects can be stored, and there are sequential
Cannot store non-OC objects, such as int\float\double\char\enum\struct, etc.
It is immutable, and once initialized, the contents of it are always fixed and cannot be deleted.
You can't add elements to it inside.
*/
1 #import<Foundation/Foundation.h>2 3 intMain () {4 @autoreleasepool {5 //create an empty array that is always empty and cannot add values to it. (Non-denatured)6Nsarray *ARR1 =[Nsarray array];7 //C language to print array elements need to traverse, OC objects can be printed directly with%@8NSLog (@"arr1 =%@", arr1);9 Ten //create an array with only one element OneNsarray *ARR2 = [Nsarray arraywithobject:@"1"]; ANSLog (@"arr2 =%@", arr2); - - //Create an array with multiple elements the //Nil represents the end of the array assignment, so Nsarray cannot store nil, and "empty" is required to use [NSNull null] - //most common ways to create (common notation) -Nsarray *ARR3 = [Nsarray arraywithobjects:@" One",@" Both",@1, [NSNullNULL],nil]; -NSLog (@"ARR3 =%@", ARR3); + - //calling an object method to create an array +Nsarray *ARR4 = [[Nsarray alloc] Initwithobjects:@"three",@" Four", nil]; ANSLog (@"ARR4 =%@", ARR4); at - //use an array to create another array -Nsarray *ARR5 =[Nsarray ARRAYWITHARRAY:ARR3]; -NSLog (@"ARR5 =%@", ARR5); - - in } - return 0; to}
The basic introduction of Black Horse programmer--oc Basic--nsaarrray