"Mu-Guest Network: basic framework for iOS Basics" Learning notes < three > Nsarray

Source: Internet
Author: User

1 intMainintargcConst Char*argv[]) {2 @autoreleasepool {3         //an OC array can store objects of different types, and basic data types cannot be stored4         //The OC array stores pointers to objects5Nsarray *array = [[Nsarray alloc] Initwithobjects:@"1",@"2",@"3",@"4",@"5", nil];6         //the length of the array7         intCount = (int) Array.count;8NSLog (@"Count:%d", count);9         //determine if an object existsTenBOOL ishave = [Array containsobject:@"3"]; One         if(ishave) { ANSLog (@"exist"); -}Else { -NSLog (@"does not exist"); the         } -         //output Last Object -NSString *str =[Array lastobject]; -NSLog (@"str =%@", str); +         //output First Object -NSString *STR2 =[Array firstobject]; +NSLog (@"str2 =%@", str2); A         //Remove the object that specifies the subscript in the array atstr = [Array Objectatindex:3]; -NSLog (@"str =%@", str); -         //You can also return the location of the subscript by specific elements. -         intindex = (int) [Array Indexofobject:@"1"]; -NSLog (@"index =%d", index);//If no element is specified, -1 is returned. -          in         //the traversal of the array (1. Basic for loop is removed by subscript check the 2.for in Fast enumeration 3. Enumerator (or iterator)) -People *p =[[People alloc] init]; toP.name =@"Zhang San"; +Nsarray *array2 = [[Nsarray alloc] Initwithobjects:@"a",@"b"P@"D",@"e", nil]; -         //1. the          for(inti =0; i<array.count; i++) { *NSString *STR1 =[Array2 objectatindex:i]; $NSLog (@"%@", str1);Panax Notoginseng         } -         //2. If you need to use fast enumeration, we need to keep the types of elements in the array consistent the          for(NSString *stinchArray) { +NSLog (@"Duang:%@", ST); A         } the         //3. Slightly +     } -     return 0; $}

"Mu-Guest Network: basic framework for iOS Basics" Learning notes < three > Nsarray

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.