2013-11-15 30 views
0

這是我的應用程序中的一個NSMutableDictionary日誌。我怎麼可能在我的NSMutableDictionary中獲取重複鍵?

{ 
one =  (
    "2013-11-15 19.47.55.jpg" 
); 
three =  (
    "2013-11-15 19.47.55.jpg" 
); 
"three" =  (
    "2013-11-15 19.45.12.jpg", 
    "2013-11-15 19.45.02.jpg" 
); 
two =  (
    "2013-11-15 19.42.21.jpg", 
    "2013-11-15 19.47.55.jpg" 
); 

}

我猜引號表示還有一些關於第二個「三」不同 - 但我不知道從哪裏開始調試這一點。如果任何人有任何建議開始尋找,我可以詳細說明,並張貼一些源代碼。我只是無法確定目前的相關內容。

編輯:

@Wain和@Vlad,所以我認爲你是對的,這裏的類的日誌:

2013-11-15 20:32:10.034 Last[9785:60b] one __NSCFString 
2013-11-15 20:32:10.036 Last[9785:60b] three __NSCFString 
2013-11-15 20:32:10.038 Last[9785:60b] three 
2013-11-15 20:32:10.039 Last[9785:60b] two __NSCFString 

無級..?

+1

你是怎麼創建它的?記錄每個鍵的類別。 – Wain

+0

請發佈一些與向字典添加值相關的代碼。 – aust

+0

那麼你是如何創建字典和鍵? – Wain

回答

3

它看起來像你的其中一個鍵被設置爲[myDict setValue:v forKey:[threeObj description]];之類的東西,另一個被設置爲[myDict setValue:otherV forKey:@"three"];

快速測試後,我想出了這個:

// Pretend MyFirstClass implements a custom -description 
MyFirstClass *o = [[MyFirstClass alloc] init]; 
NSMutableDictionary *d = [NSMutableDictionary dictionary]; 

// We get "\"Three\"" 
NSString *key = [o description]; 

[d setObject:[NSNumber numberWithBool:YES] forKey:[key lowercaseString]]; 

// In another part of code you're doing something like this: 
key = @"Three"; 
[d setObject:[NSNumber numberWithInt:1000] forKey:[key lowercaseString]]; 

輸出:

2013-11-15 14:29:21.942 Dummy[31958:c07] { 
    "three" = 1; 
    three = 1000; 
} 

這肯定是兩個獨特的密鑰。我會檢查你的代碼以確保沒有發生這種情況。也許你有多個區域設置值並以不同方式處理密鑰創建。

+0

我正在使用[key lowercaseString],可以嗎? –

+0

你在哪裏得到鑰匙?我認爲你的問題在於產生密鑰的地方。 – aust

+0

如果您通過執行以下操作獲取密鑰:key = [myObj description];然後調用lowercaseString,這將是你的問題。 – aust

0

我會首先檢查重複類的類類型。不能真的以其他方式重複。 嘗試在調試NSStringFromClass([對象類])打印出您的字典中的每個對象和鍵。