Skip to content

Commit

Permalink
Iteration in Dictionaries, classic, fast and blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Halgravez committed Mar 28, 2017
1 parent b4c5c9c commit c3004eb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Iteracion/Iteracion/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ int main(int argc, const char * argv[]) {
[list enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"El elemento %lu vale %@", idx, obj);
}];


//NSDictionary
NSDictionary *dict = @{@"uno":@1, @"dos":@2, @"tres":@3};

//Classic way
NSArray *keys = dict.allKeys;
for (int i = 0; i < keys.count; i++) {
NSLog(@"La clave %@ corresponde al objeto %@", keys[i], dict[keys[i]]);
}

//Fast
for (id key in keys) {
NSLog(@"La clave %@ corresponde al objeto %@", key, dict[key]);
}

[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSLog(@"La clave %@ corresponde al objeto %@", key, obj);
}];
}
return 0;
}

0 comments on commit c3004eb

Please sign in to comment.