ios claims the file has been written to, but the changes never actually save, as if they remain in buffer. Do I have to flush or something?
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myFilePath = [[NSBundle mainBundle]
pathForResource:@"MyFile"
ofType:@"txt"];
NSLog(@"\n\nPath = \n%@", myFilePath);
NSString *myFileContents = [NSString stringWithContentsOfFile:myFilePath
encoding:NSUTF8StringEncoding
error:nil];
NSLog(@"\n\nContents = \n%@", myFileContents);
[@"This line will be written to file" writeToFile:myFilePath
atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSString *changedContents = [NSString stringWithContentsOfFile:myFilePath
encoding:NSUTF8StringEncoding
error:nil];
NSLog(@"\n\nChanged Contents = \n%@", changedContents);
}
Output:
Path =
/Users/hamzeh/Library/Application Support/iPhone Simulator/5.1/Applications/2B318687-A745-4CD9-85BA-52A01AB76F6E/savepersistentdata_tutorial.app/MyFile.txt
Contents =
This is a text file.
The file will be displayed on the iPhone.
That is all for now.
Changed Contents =
This line will be written to file
This is the output I get every time I run, so the changes don't actually get written to the file.
Thanks for the help.