I have a CollectionView that I am using images from Firebase Storage to fill. I store the images under 'userId' node. I want to check the files existence in bulk that are available under the node, so I can store them in an array.
I tried to retrieve the urls separately for each one, however, I believe this is a very wrong approach. But, I couldn't figure out how to do it in most efficient way and where to put collectionView.reload()
. This is what I did:
let storage = FIRStorage.storage()
let firstImageRef = storage.referenceForURL("gs:storageUrl").child(uid).child("profile.jpg")
firstImageRef.downloadURLWithCompletion { (URL, error) -> Void in
if (error != nil) {
print(error)
} else {
if let url = URL {
self.databaseImagesOrder.append(url)
}
}
}
let secondImageRef = storage.referenceForURL("gs:storageUrl").child(uid).child("second_pic.jpg")
secondImageRef.downloadURLWithCompletion { (URL, error) -> Void in
if (error != nil) {
print(error)
} else {
if let url = URL {
self.databaseImagesOrder.append(url)
}
}
}
// etc..
collectionView.reloadData()
Also, is it better to fetch the image as NSData better than fetching the urls first and then fetching the images? If so, how can I retrieve images in bulk from Firebase Storage?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…