I am trying to write a list to a text file that is included in my project (Deck.txt) the relevant code is as follows:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Deck" ofType:@"txt"];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
deck = [[NSString alloc]initWithFormat: @"%@\n%@ %@",file, txtQuantity.text, cardName];
//[deck writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
[fileHandle writeData:[deck dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
When I run the code it will not save to the text document however, or at least not the one included in my project. It will still create the list and read from the file all the data that I am trying to write, but when I close the program no changes are made to the text document. Any help would be most appreciated.
If you’ve already got your NSData instance, you can certainly just write the data to the built in document directory on the device. With a bit of searching, it’s not hard to find the location when run from the simulator for checking purposes.
This will certainly write to a file in your documents directory. It should only be a matter of altering your code to read from the directory.