从存储中下载图像时出现可选错误,我已将字符串转换为 URL

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

从 firebase 存储下载图像时可选错误,我正在将字符串转换为 URL 以下载图像

这是发生错误的代码,如果需要更多代码请告诉我

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

您必须(安全地)解包 URL 实例

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

甚至(如果 postuserprofileImagUrl 也是可选的)

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