Created
April 14, 2020 13:09
-
-
Save Esquilli/c479768bfa840dd318ba1a3ea142eb3c to your computer and use it in GitHub Desktop.
Write to file in Documents directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get documents directory | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
// File | |
NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt", documentsDirectory]; | |
// Write to file | |
NSString *string = @"Example"; | |
[string writeToFile:fileName | |
atomically:NO | |
encoding:NSStringEncodingConversionAllowLossy | |
error:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment