oc数组遍历

#import <Foundation/Foundation.h>

//数组遍历(枚举)对集合中的元素依此不重复的进行遍历

int main(int argc, const char * argv[]) {

    @autoreleasepool {

NSArray *arr=@[@"MON",@"TUE",@"WED",@"THU",@"FRI",@"SAT",@"SUN"];

    //下标遍历

        for (int i=0; i<[arr count]; i++) {

            

            NSString *element=[arr objectAtIndex:i];

            NSLog(@"%@",element);

        }

        NSLog(@" ");

        for (int i=0; i<[arr count]; i++) {

            NSLog(@"%@",arr[i]);

        }

        NSLog(@" ");

        //for in 遍历性高

        for (NSString *str in arr) {

            

            NSLog(@"%@",str);

        }

        NSLog(@" ");

        //id当 不确定数组元素的类型时,选择使用de

        //id NSObject instancetype

        for (id str in arr) {

            NSLog(@"%@",str);

        }

    

        

    }

    return 0;

}

原文地址:https://www.cnblogs.com/shaowenlong/p/5121733.html