嗨,我有一个NSdictionary,其中我添加了一个带有键“国家”的数组。现在我将这个字典的值放入数组并按字母顺序对数组进行排序。现在我想将此数组添加到我的字典中(也就是说,我想用新的排序数组更新字典并从中删除旧数组)。 ....... 这该怎么做
我的代码如下
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:@"Countries"];
NSArray *tmpary = [countriesToLiveInDict valueForKey:@"Countries"];
NSLog(@"ary value is %@",ary);
NSArray *sortedArray = [tmpary sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSLog(@"sortedArray is %@",sortedArray);
在这里我想删除countryToToInInArray并将其替换为具有相同键值即国家的sortedArray
提前致谢..
最佳答案
首先,您需要使用NSMutableDictionary
并放置以下代码:
[countriesToLiveInDict removeObjectForKey:@"Countries"];
[countriesToLiveInDict setObject:sortedArray forKey:@"Countries"];