1.使用for循环遍历数组
NSArray * array = @[@"one",@"two",@"three"]; for (int i = 0; i < array.count; i++) { NSString * str = array[i]; NSLog(@"array[%d] = %@",i,str); }
2、使用改进版循环
for (NSString * str in array) { NSLog(@"str = %@",str); }
3、使用枚举器
NSArray * array3 = @[@"one",@"two",@"three"]; NSEnumerator * enumerateor = [array3 objectEnumerator]; NSString * value; while (value = [enumerateor nextObject]) { NSLog(@"enum str %@",value); }
时间: 2024-10-09 22:16:28