1.for循環(huán)遍歷
//for循環(huán)遍歷
NSArray *array = @[@1,@2,@3,@4,@5];
for (int i = 0; i < array.count; i++) {
NSLog(@"array[i]=%@",array[i]);
}
//for循環(huán)反向遍歷
for (NSInteger i = array.count-1; i >= 0; i--) {
NSLog(@"array[i]=%@", array[i]);
}
2.NSEnumerator遍歷法
//NSEnumerator遍歷法
NSEnumerator *enumerator = [array objectEnumerator];
id object;
while ((object = [enumerator nextObject]) != nil) {
NSLog(@"object=%@",object);
}
//NSEnumerator遍歷法反向遍歷
NSEnumerator *reverseenu = [array reverseObjectEnumerator];
id object;
while ((object = [reverseenu nextObject]) != nil) {
NSLog(@"object=%@",object1);
}
3.快速遍歷法
//快速遍歷法
for (NSObject *obj in array) {
NSLog(@"obj=%@",obj);
}
//快速遍歷法反向遍歷
for (NSObject *obj in [array reverseObjectEnumerator]) {
NSLog(@"obj=%@",obj);
}
4.塊枚舉法
//塊枚舉法
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"idx=%zd,obj=%@",idx,obj);
}];
//塊枚舉法反向遍歷
[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"idx=%zd,obj=%@",idx,obj);
}];