Download and save image in swift 2 [closed]

0

I have a web service where is a photo and I need to download it to my device, save it and also create a folder where you should save the image from swift 2.

How can I do it? How do I do it?

Thank you.

    
asked by Andres Guillermo Castellanos A 13.06.2016 в 15:34
source

1 answer

1

This works in a Playground:

let url = NSURL(string: "http://science-all.com/images/wallpapers/beach-images/beach-images-5.jpg")
let data = NSData(contentsOfURL: url!)
let image = UIImage(data: data!)

It is recommended that you do not do this in the "main thread" so as not to block the UI while downloading the image.

To save the image to disk, the class NSData has writeToFile methods for that.

    
answered by 13.06.2016 в 16:55