Reputation: 429
I'm trying to implement a feed for images using Firebase Storage, think of it like the Instagram photo feed. My Problem:
I tried downloading the images from the reference like this:
let storageRef = storage.reference()
for i in 0...10 {
let imageRef = storageRef.child("images/" + String(i) + ".jpg")
imageRef.dataWithMaxSize((10 * 1024 * 1024), completion: { (data, error) -> Void in
if (error != nil) {
print(error)
} else {
let image: UIImage! = UIImage(data: data!)
self.downloadedPhotos.append(image) //downloadedPhotos is an array of UIImages
self.configureFeed() //takes care of some UI
}
})
}
Here I run into the obvious problem: I've only downloaded 10 images, called "1","2",..., "10"
Thank you guys really much for any help!
Upvotes: 0
Views: 809
Reputation: 15953
Let's handle these one at a time:
I'd take a look at the many other questions like this: Retrieving image from Firebase Storage using Swift
See above.
You can use Object Lifecycle Management to delete images after a certain time. Deleting them from the database would be harder--maybe an integration with Google Cloud Functions GCS notifications could sync this.
I totally recommend using an image loader like SDWebImage or PINRemoteImage after pulling the download image from the realtime database.
Upvotes: 1