可复制代码:
NSDictionary * dic = @{@"name":@"梁森", @"age":@"27"};
NSEnumerator * enumerator = [dic keyEnumerator];
id key;
while ((key = [enumerator nextObject]) != nil) {
id value = dic[key];
NSLog(@"value:%@", value);
}
NSArray * arr = @[@"1", @"2", @"3"];
NSEnumerator * arrEnumerator = [arr objectEnumerator];
id object;
while ((object = [arrEnumerator nextObject]) != nil) {
NSLog(@"object:%@", object);
}
最快、最新的“块枚举法”:
[arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"idx:%lu---obj:%@",idx, obj);
}];
网友评论