user11093104
user11093104

Reputation:

There is an optional error while downloading the image from the storage, I have converted the string to URL

There is an error for optional while downloading the image from the firebase storage, I am converting the string to URL to download the image

here is the code where the error is occuring , if any more code is required do let me know

let imageUrl = URL(string: post._postuserprofileImagUrl)
        ImageService.getImage(withURL: imageUrl) { image in
            self.profileImageView.image = image
        }

Upvotes: 3

Views: 67

Answers (1)

vadian
vadian

Reputation: 285039

You have to (safely) unwrap the URL instance

if let imageUrl = URL(string: post._postuserprofileImagUrl) {
        ImageService.getImage(withURL: imageUrl) { image in
            self.profileImageView.image = image
        }
}

Or even (if postuserprofileImagUrl is optional, too)

if let userprofileImagUrl =  post._postuserprofileImagUrl,
   let imageUrl = URL(string: userprofileImagUrl) {
        ImageService.getImage(withURL: imageUrl) { image in
            self.profileImageView.image = image
        }
}

Upvotes: 2

Related Questions