0

我试图在 for 循环中获取 NSMutableDictionary 的 KEY 的名称。但是我很沮丧,因为我找不到正确的函数来只获取 KEY 而不必引用对象。

我会很感激一些指导。我想要的关键是一个字符串

NSMutableDictionary* myMutaDictionary = @{ @"theValeIwantOne":@{key:value},
                             @"theValeIwantTwo":@{key:value}
                           };

for (NSDictionary* myDictionary in myMutaDictionary) {
    NSString* key1 = //... code to get theValeIwantOne and theValeIwantTow;
}

我来自 PHP,这个操作很简单

foreach ($variable as $key => $value) {

    $thisIsMyKeyName = $key;
    $thisIsTheValueOfThatKey = $value;
}
4

1 回答 1

2

听起来你正在寻找keyEnumerator

for (NSString *key in [dict keyEnumerator]) {
    NSString *value = [dict objectForKey:key];
}
于 2013-05-14T21:39:43.490 回答