iOS字典遍历

2017-03-13  本文已影响58人  orilme

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;

}

}];
上一篇 下一篇

猜你喜欢

热点阅读