Quantcast
Viewing all articles
Browse latest Browse all 10

Answer by neoneye for How do I save a UIImage to a file?

extension UIImage {    /// Save PNG in the Documents directory    func save(_ name: String) {        let path: String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!        let url = URL(fileURLWithPath: path).appendingPathComponent(name)        try! UIImagePNGRepresentation(self)?.write(to: url)        print("saved image at \(url)")    }}// Usage: Saves file in the Documents directoryimage.save("climate_model_2017.png")

Viewing all articles
Browse latest Browse all 10

Trending Articles