ios - 从存储下载图像时出现可选错误,我已将字符串转换为 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
}
}
推荐阅读
- properties - 这部分不会变色
- swift - 尝试在 UIImageView 上使用 SDWebImage 扩展时出错
- jquery - HTML & CSS 垂直滚动条指示器
- linux - Perl 中的这个命令有什么作用?
- c# - C# 7.3 引用返回与 pinvoke
- xcode - 如何从构建目标中删除无关的部署目标设置
- angular - 如何在angular4中使用每个
- python - 如何在 Google Analytics API DimensionFilter 中有多个表达式?
- typescript - 在 Ramda 的管道函数上扩展数组给出类型错误“预期 1-6 但得到 0 或更多”
- python - Python for i in range(2,2): print(i) i 变量包含什么,它不包含值 2?