Skip to content

Instantly share code, notes, and snippets.

@carljparker
Last active August 29, 2015 14:26
Show Gist options
  • Save carljparker/4d7391a8d9f58827d6fa to your computer and use it in GitHub Desktop.
Save carljparker/4d7391a8d9f58827d6fa to your computer and use it in GitHub Desktop.
iOS: Save an image file to the Documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.jpg"]; //Add the file name
[((Image *)obj).scaledImage writeToFile:filePath atomically:YES]; //Write the file
//
// retrieve the image
//
NSData *pngData = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [UIImage imageWithData:pngData];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment