2013-04-29 92 views
0

我設置valuekey像這樣:是否可以在一個鍵下設置一個NSMutableDictionary鍵?

[mutableDict setObject:@"Object to set" forKey:@"KeyOne"]; 

這工作,但現在我想補充一個value"Key one"下,像這樣:

[mutableDict setObject:@"Object a" forKey:@"KeyOne/detailsOnKey"]; 

這甚至可能嗎?所有的幫助表示讚賞

+0

不,你不能設置一個鍵的方式鍵「下」我認爲你正在嘗試去做。我相信還有另一種方法可以實現你想要的東西。你打算做什麼? – rdelmar 2013-04-29 03:39:06

回答

1

聽起來像你想你的字典裏一本字典,dawg

mutableDict[@"KeyOne"] = @{@"detailsOnKey": @"Object"} 

然後你就可以訪問該嵌套的字典是這樣的:

mutableDict[@"KeyOne"][@"detailsOnKey"] 
+0

謝謝,這工作完美! – user2272641 2013-04-29 03:49:47

0

您可以使用此多個詞典。

//add a dictionary as the object for KeyOne 
[mutableDict setObject:[[NSMutableDictionary alloc] init] forKey:@"KeyOne"]; 

//add "Object a" under key one 
[(NSMutableDictionary *)[mutableDict objectForKey:@"KeyOne"] setObject:@"Object a" forKey:@"detailsOnKey"]; 

//如何獲得keyone/detailsonkey回?,這樣你可以把它找回來

id objectA = [(NSMutableDictionary *)[mutableDict objectForKey:@"KeyOne"] objectForKey:@"detailsOnKey"]; 
相關問題