How can I remove last line in a file in iOS.
Below is the code that let’s me go to the end of file but then I don’t know how to remove that last line.
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the documents directory:
NSString *file = [NSString stringWithFormat:@"%@/%@.daa", documentsDirectory, MFILE_NAME];
NSFileHandle *aFileHandle = [NSFileHandle fileHandleForWritingAtPath:file];
//setting aFileHandle to write at the end of the file
[aFileHandle truncateFileAtOffset:[aFileHandle seekToEndOfFile]];
Thanks for your help.
Ok, after some documentation reading this is what I ended up with:
If you know a better way please let me know.