1、遍历键值
for (NSString *value in [dictionary allValues]) {
NSLog(@"value: %@", value);
}
2、遍历键名
for (NSString *key in [dictionary allKeys]) {
NSLog(@"key: %@", key);
}
3、enumerateKeysAndObjectsUsingBlock方法
[dictionaryenumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSLog(@"key = %@ and value = %@", key, obj);
if ([key isEqualToString:@"yourkey"]) {
*stop = YES;
}
}];
网友评论