Search code examples
objective-cnsfilemanager

Saving images from an array to a file in filemanager


I have been working with nsfilemanager and trying to save images as files where the images are obtained from an array. But i couldn't find a solution.


Solution

  • To save an image, you can do the following :

    NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(yourImage, 1.0f)];
    [data writeToFile:theDesiredPath atomically:YES]);
    

    So if you want to save the images contained into your array, simply iterate your array with a for statement and call theses two lines of code...

    For example :

    for (UIImage *img in arrayOfImages){
        NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(img, 1.0f)];
        [data writeToFile:theDesiredPath atomically:YES]);
    }