Skip to content

Instantly share code, notes, and snippets.

@kyktommy
Created July 22, 2013 16:07
Show Gist options
  • Save kyktommy/6055086 to your computer and use it in GitHub Desktop.
Save kyktommy/6055086 to your computer and use it in GitHub Desktop.
IOS - File write content to file
// Define directory and file path
NSString *documentDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [documentDir stringByAppendingPathComponent:@"file1.txt"];
// Write NSArray to file
NSArray *numbers = @[@12, @124, @214214];
[numbers writeToFile: filePath atomically:YES];
NSError *error;
// List all Files in the directory
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentDir error: &error];
// Remove Item
[fileManager removeItemAtPath:filePath error: &error];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment