Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save an NSString as a .txt file on my apps local documents directory?

Tags:

How do I save an NSString as a .txt file on my apps local documents directory (UTF-8)?

like image 403
RexOnRoids Avatar asked Feb 02 '10 13:02

RexOnRoids


1 Answers

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory  NSError *error; BOOL succeed = [myString writeToFile:[documentsDirectory stringByAppendingPathComponent:@"myfile.txt"]       atomically:YES encoding:NSUTF8StringEncoding error:&error]; if (!succeed){     // Handle error here } 
like image 137
Vladimir Avatar answered Oct 09 '22 01:10

Vladimir