Reputation:
In Xcode 10 UIImagePNGRepresention()
worked ,but in the new Xcode it changed to .pngData() . And I'm not sure how to use the new instance method properly.
I'm trying to convert a UIImage
to NSData
and not sure how to do that on .pngData()
This is how I did it on the old UIImagePNGRepresentation()
:
let imageData:NSData = UIImagePNGRepresentation(image!)! as NSData
I want to know how to do that ^ in the new intance method
Upvotes: 1
Views: 6860
Reputation: 21
.pngData() function returns data object containing png data or nil.
So you can use this function in the following way:
let imageData = image!.pngData()!
See https://developer.apple.com/documentation/uikit/uiimage/1624096-pngdata
Upvotes: 2