The basic introduction of Black Horse programmer--oc Basic--nsaarrray

Source: Internet
Author: User

------<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

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.