// // main.m // 遍历 // // Created by syrcfwzx on 16/1/7. // Copyright (c) 2016年 syrcfwzx. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSArray* array = @[@"one",@"two",@"three"]; //下标遍历 for(int i=0;i<[array count];i++) { id obj = [array objectAtIndex:i]; NSLog(@"%@",obj); } //for in语法 for(id obj in array) { NSLog(@"%@",obj); } //枚举器 NSString* str = nil; NSEnumerator* enumerator = [array objectEnumerator]; while (str = [enumerator nextObject]) { NSLog(@"%@",str); } //block语法 [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"idx=%ld obj=%@",idx,obj); }]; } return 0; }