NSArray *array =@[@"23",@"11",@"33",@"44",@"55",@"66"];
//遍历1
for (int i =0; i < array.count; i++) {
}
//遍历2
for (id objin array) {
}
//遍历3
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx,BOOL * _Nonnull stop) {
// if ([obj isEqual: @"23"]) {
// NSLog(@"obj===%@",obj);
// }
if (idx == 1) {
* stop = YES;//用来停止遍历
}
NSLog(@"%@====== %lu",obj,(unsignedlong)idx);
}];
NSDictionary *dic = @{@"姓名":@"Scarlett",
@"年龄":@"26",
@"性别":@"女"};
字典遍历
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSLog(@"%@======%@",key,obj);
}];