user12448776
user12448776

Reputation:

UIImagePNGRepresentation() has been replaced by .pngdata()

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

Answers (2)

Akarsh
Akarsh

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

Sulthan
Sulthan

Reputation: 130102

Simply:

let imageData = image!.pngData()! as NSData

See UIImage.pngData()

Upvotes: 5

Related Questions