我正在爲我的應用發送一個更新,這將需要更新用戶數據庫。我將數據存儲在屬性列表中。基本上,陣列中的每個點都NSMutableDictionaries,我需要添加鍵,更換鍵等在枚舉時替換數組中的對象?
我嘗試以下,但它產生的NSException,
for (NSMutableDictionary *dict in myArray) {
if ([dict objectForKey:@"someKey"] == nil) {
//Extract the value of the old key and remove the old key
int oldValue = [[dict objectForKey:@"key1"] intValue];
[dict removeObjectForKey:@"key1"];
[dict setValue:[NSString stringWithFormat:@"%d pts", oldValue] forKey:@"newKey"];
//Add new keys to dictionnary
[dict setValue:@"some value" forKey:@"key2"];
[dict setValue:@"some value" forKey:@"key3"];
[dict setValue:@"some value" forKey:@"key4"];
[self.myArray replaceObjectAtIndex:index withObject:dict];
}
我應該怎麼做來更新我的數據以上述方式?
真棒!非常感謝,我不能相信這是多麼簡單 – cgossain 2011-05-17 20:54:24