在我的第一個函數中,我創建了一個NSMutableDictionary並將其保存在一個數組中。MutableDictionary變得不可變
NSMutableArray* tempPlayersArray = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults] arrayForKey: @"kgpsTempArray"]];
NSMutableDictionary *tempPlayerDictArray = [[NSMutableDictionary alloc] init];
if (!(userDeviceName)) {
[tempPlayerDictArray setValue:userDeviceName forKey:@"DeviceName"];
}else{
[tempPlayerDictArray setValue:@"empty" forKey:@"DeviceName"];
}
[tempPlayersArray addObject:tempPlayerDictArray];
[defaults setObject:tempPlayersArray forKey:@"kgpsTempArray"];
[defaults synchronize];
在我的第二個函數中,我把它作爲NSCFDictionary - 這是不可變的。
NSMutableArray* tempPlayersArray = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults] arrayForKey: @"kgpsTempArray"]];
NSMutableDictionary *dictionaryForSearching = [[NSMutableDictionary alloc] init];
NSLog(@"%@",[dictionaryForSearching class]);
dictionaryForSearching = [tempPlayersArray objectAtIndex:index];
NSLog(@"%@",[[tempPlayersArray objectAtIndex:index] class]);
NSLog(@"%@",[dictionaryForSearching class]);
第一個日誌顯示「NSDictionaryM」。
第二個日誌顯示「NSCFDictionary」。
而第三個顯示「NSCFDictionary」以及...
任何人都可以解釋我爲什麼?以及如何解決它?
非常感謝! – 2013-03-06 11:11:24