How to Use nsarray quick Enumeration

Source: Internet
Author: User

The quick enumeration method creates an array:

 

The principle of the quick enumeration method is similar to that of enumeration, but the method is simpler and clearer.

 

Just like the quick enumeration method, you need to first create an immutable array, and then print the elements in the array one by one through quick enumeration.

 

Let's take a look at the detailed example below:

#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        NSArray *array = [[NSArray alloc]initWithObjects:@"One One", @"Tow", @"Three", nil];                //这里的obj在进去循环的时候一开始就是One One的地址, 到后再到Tow, 以此类推.        for (id obj in array){            NSLog(@"\n%@", obj);        }        //它和枚举法的原理一样, 只是写法比枚举法稍微简单一些.        [array release];    }    return 0;}

Output result:

2014-10-12 14:30:23.208 RapidEnumNSArray[1583:303] One One2014-10-12 14:30:23.210 RapidEnumNSArray[1583:303] Tow2014-10-12 14:30:23.210 RapidEnumNSArray[1583:303] ThreeProgram ended with exit code: 0

 

How to Use nsarray quick Enumeration

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.