0

I have an app that is collecting data from user inputs on a pretty regular basis. I'm writing the data to a text file and saving it to the disk. I usually call writeToFile:, but the issue with that is that it is constantly overwritten each time. I can't create different file names either because I'd like to keep it all in one file for the user to access later. I'm not sure how to even go about this, does anyone have any recommendations?

- (void)saveToTextFile {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"usernotes"];

    NSString *savedString = [NSString stringWithFormat:@" First:%@  Second: %@", firstOne, secondOne];

    [savedString appendToFile:@"usernotes"];

}

I'm getting an error that says No visible interface for NSString declares the selector appendToFile.

Henry F
  • 4,960
  • 11
  • 55
  • 98

1 Answers1

1

have you tried appendToFile: rather than writeToFile:? Append should add the new code at the bottom of the file, if I am not mistaken.

pinmonkeyiii
  • 191
  • 1
  • 3
  • Wow really? I have not. I'll give that a shot right now and post back. – Henry F Jul 12 '13 at 18:13
  • I just tried it but got an error. I updated my code above. – Henry F Jul 12 '13 at 18:30
  • My fault, I missed that this was ios related. Try this answer from a related question, the accepted answer may point you in the correct direction: http://stackoverflow.com/questions/11106584/ios-appending-to-end-of-file-with-nsmutablestring – pinmonkeyiii Jul 12 '13 at 18:44