问题
I created the below function to fetch image from firebase storage:
func downloadImageFromFirebase(_ imageNameOnFireBase: String, imageViewToBeFilled: UIImageView) {
let storage = Storage.storage()
let reference: StorageReference = storage.reference().child(imageNameOnFireBase)
reference.downloadURL { url , error in
if error != nil {
print(error!.localizedDescription)
imageViewToBeFilled.image = UIImage(named: "default")
} else {
if let url = url {
do {
let data = try Data.init(contentsOf: url)
imageViewToBeFilled.image = UIImage(data: data)
} catch {
print("Error fetching URL")
imageViewToBeFilled.image = UIImage(named: "default")
}
}
}
}
}
When using the function many times it causes loading delay , How can i approach faster and more reliable way of downloading the images ?
回答1:
You should be able to fetch images from Firebase with URLs, and using SDWebImage it will enable your app to have very fast loading and scrolling times as the images are only loaded once. An excellent tutorial for this can be found here: https://www.youtube.com/watch?v=XPAaxF0rQy0
(He teaches it with Firebase Storage)
来源:https://stackoverflow.com/questions/61857042/sdwebimage-with-firebase