从 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
}
}
关于ios - 从存储中下载图像时出现可选错误,我已将字符串转换为 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57873344/