Ios 从存储器下载图像时出现可选错误,我已将字符串转换为URL
从firebase存储下载图像时,optional出现错误,我正在将字符串转换为URL以下载图像 这是发生错误的代码,如果需要更多代码,请告诉我Ios 从存储器下载图像时出现可选错误,我已将字符串转换为URL,ios,swift,firebase,google-cloud-firestore,storage,Ios,Swift,Firebase,Google Cloud Firestore,Storage,从firebase存储下载图像时,optional出现错误,我正在将字符串转换为URL以下载图像 这是发生错误的代码,如果需要更多代码,请告诉我 let imageUrl = URL(string: post._postuserprofileImagUrl) ImageService.getImage(withURL: imageUrl) { image in self.profileImageView.image = image } 您
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
}
}
甚至(如果posterprofileimagurl
也是可选的)
试着在帖子后面加上“!”。\u posturesprofileimagurl喜欢帖子。\u posturesprofileimagurl!强制展开,或发布。\u positionersprofileimagurl??"". 检查这是否有效?不,它指向(withURL:imageUrl)并给出消息“可选类型'URL'的值”必须被解包为类型'URL'的值。“我想这在这里已经讨论得够多了,不是吗?@Sh_Khan根据评论,代码似乎没有崩溃,所以它实际上不是一个副本,它没有给出任何可选错误,但它还没有下载图像,让我检查一下有什么问题
if let userprofileImagUrl = post._postuserprofileImagUrl,
let imageUrl = URL(string: userprofileImagUrl) {
ImageService.getImage(withURL: imageUrl) { image in
self.profileImageView.image = image
}
}