Convert UIImage to NSData and convert back to UIImage in Swift?
I'm trying to save a UIImage to NSData and then read the NSData back to a new UIImage in Swift. To convert the UIImage to NSData I'm using the following code: let imageData: NSData = UIImagePNGRepresentation(myImage) How do I convert imageData (i.e., NSData ) back to a new UIImage ? algal UIImage(data:imageData,scale:1.0) presuming the image's scale is 1. In swift 4.2, use below code for get Data(). image.pngData() Ivan Sinigaglia Thanks. Helped me a lot. Converted to Swift 3 and worked To save: let data = UIImagePNGRepresentation(image) To load: let image = UIImage(data: data) Use