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