Anvil
Anvil

Reputation: 1865

Cannot convert value of type 'Data?' to expected argument type 'UIImage

I'm trying to get the data of an image but I'm getting this error:

Cannot convert value of type 'Data?' to expected argument type 'UIImage'

The code:

if let image = profileImageView.image {
    if let imageData = UIImagePNGRepresentation(image.pngData()) {
        PFUser.current()?["photo"] = PFFileObject(name: "profile.png", data: imageData)
    }
}    

Where have I gone wrong?

Upvotes: 0

Views: 5633

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

The initializer of UIImagePNGRepresentation takes a UIImage instance not Data instance , so replace

if let imageData = UIImagePNGRepresentation(image.pngData()) {

with

if let imageData = UIImagePNGRepresentation(image) {

OR better use the latest Way

if let imageData = image.pngData() {   

Upvotes: 2

Related Questions