我正在尝试从UIImageView中存储在Firebase数据库中的URL中显示图像。该路径返回正确的URL(我可以在控制台中看到它);但是,该图像不会出现在连接的图像视图中。有什么建议么?
let imgRef = Database.database().reference(fromURL: "https://ryan-915d2.firebaseio.com/")
imgRef.child("locations")
.child("111 Smith Street")
.child("building ")
.child("image")
.observeSingleEvent(of: .value, with: { snapshot in
if let url = snapshot.value as? String {
print(snapshot, "I found the image")
URLSession.shared.dataTask(with: URL(string: url)!) { data, response, error in
if error == nil {
let image = UIImage(data: data!)
DispatchQueue.main.async {
self.imageView.image = image
}
}
}.resume()
}
}
)}
}