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.
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.
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.