1
我有plist包含字典說dict
和字典我有3個數組的鍵A,B,C。現在我想在特定情況下在A,B和C中添加一個項目。爲此我這樣做...寫數據到Plist
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingString:@"MovingChecklist.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if (![fileManager fileExistsAtPath: plistPath])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"MovingChecklist" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: plistPath error:&error];
}
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
NSArray *array1 = [dict objectForKey:@"A"];
NSArray *array2 = [dict objectForKey:@"B"];
NSArray *array3 = [dict objectForKey:@"C"];
NSMutableArray *myArray;
if (currentMovingList == KMovingListTypeA) {
myArray = [NSMutableArray arrayWithArray:array1];
[myArray addObject:nameTextView.text];
[dict setValue:myArray forKey:@"A"];
}
if (currentMovingList == KMovingListTypeB) {
myArray = [NSMutableArray arrayWithArray:array2];
[myArray addObject:nameTextView.text];
[dict setValue:myArray forKey:@"B"];
}
if (currentMovingList == KMovingListTypeC) {
myArray = [NSMutableArray arrayWithArray:array3];
[myArray addObject:nameTextView.text];
[dict setValue:myArray forKey:@"C"];
}
[dict writeToFile:plistPath atomically: YES];
但是plist沒有改變。建議我在做什麼錯誤。
日Thnx Neo..this是一個愚蠢的和愚蠢的錯誤...... – iCoder4777
你是歡迎的。 – Neo