I wrote this small bit of code to write to a plist file. I am not getting any errors or warnings from XCode, so I am really lost. "Root" is not defined in this code section, but it is just a dictionary of the data that I pulled from the plist.
Does anyone have an idea of why this would not write to a plist file? It literally does not change the file at all.
NSMutableArray *newReports = [[NSMutableArray alloc] init];
newReports = [[Root objectForKey:@"Reports"] mutableCopy ];
//Creating data model for new report
NSMutableDictionary *newReport = [[NSMutableDictionary alloc] init];
NSString *tempTitle = titleField.text;
NSString *tempEmployee = employeeField.text;
NSArray *tempNodes = [[NSArray alloc] init];
[newReport setObject:tempTitle forKey:@"Title"];
[newReport setObject:tempEmployee forKey:@"Employee"];
[newReport setObject:tempNodes forKey:@"Nodes"];
[newReports addObject:newReport];
NSMutableDictionary *newRoot = [[NSMutableDictionary alloc] init];
[newRoot setObject:newReports forKey:@"Reports"];
//Writing data to plist
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *filePath = [Path stringByAppendingPathComponent:@"data.plist"];
[newRoot writeToFile:filePath atomically: YES];
Thanks for the help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…