如何获取NSMutableDictionary的Key的名称

时间:2013-05-14 21:36:24

标签: objective-c

我试图在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;
}

1 个答案:

答案 0 :(得分:2)

听起来像是在寻找keyEnumerator

for (NSString *key in [dict keyEnumerator]) {
    NSString *value = [dict objectForKey:key];
}