user11386514
user11386514

Reputation:

How To Properly Update User Profile Image

What is the updated code to upload user profileImage, I got an error trying to update user profileImage.

How do I fix this error?

Cannot invoke initializer for type 'UIImage' with an argument list of type '(@escaping () -> ())'

self.ProfileImage.image = UIImage{data; data!}

Upvotes: 0

Views: 217

Answers (2)

SwiftNinja95
SwiftNinja95

Reputation: 157

There are few issues with your code such as you are using {} instead of () . So , the code will actually look like ...

self.ProfileImage.image = UIImage(data: data!)

but since data is optional value , it can come as nil if not handled properly. This will lead to crash within your app . So use optional binding in such cases to check whether the data variables actually contain any values , like the code below.

    if let imageData = data{
        self.ProfileImage.image = UIImage(data: imageData)
    }else{
        self.ProfileImage.image = UIImage(named : "image_when_no_value_is_present")
}

Upvotes: 0

Keshu R.
Keshu R.

Reputation: 5225

You are using { braces } whereas you need to use ( round brackets )

myImageView.image = UIImage(data: imageData)

Upvotes: 1

Related Questions