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")
↧
Answer by neoneye for How do I save a UIImage to a file?
↧