I've been trying to save to a property list file, however it's not working as its only saving the object to the array not the actual file itself, meaning that what it saves isn't obviously persisting.
[[category objectAtIndex:questionCounter] replaceObjectAtIndex:5 withObject:myString];
[category writeToFile:filePath atomically:YES];
I'm using this earlier on to save the property list files to the document directory so that I can edit and save to them:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistFilePath = [documentsDirectory stringByAppendingPathComponent:fileNameFull];
if([[NSFileManager defaultManager] fileExistsAtPath:plistFilePath]) {
category = [NSMutableArray arrayWithContentsOfFile:plistFilePath];
NSLog(@"Files exist.");
}
else {
filePath = [[NSBundle mainBundle] pathForResource:fileNamer ofType:@"plist"];
category = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"Files have been created.");
}
My property list is made up of arrays, within those arrays I'm trying to save my object (the string). I have a feeling it's something trivial but I can't spot it.
When you are trying to save your array, you are passing in filePath
which points to the main bundle directory, which you can't write to. You want to use plistFilePath
instead, like so:
[category writeToFile:plistFilePath atomically:YES];