Firestore/Firebase is a great backend platform for small teams and independent developers but it does require a good understanding of the basics to get started and be productive. This is a ‘hands on’ tutorial where we’re going to build a simple photo albums application that allows a user to manage their albums and photos collection. In the tutorial we’re going to use the two arguably most important Firestore/Firebase services: Firestore real-time database and Firebase Storage. We’re also going to briefly touch on Firestore Functions in one of the challenges. Let’s get started by cloning the starter project, you can always switch to the master branch later if you would like to see the final finished version.
One of the challenges every iOS developer faces on regular basis is loading data from the server, while keeping the UI responsive.
In this article we’re going to build a simple CollectionView Controller that fetches images from the server asynchronously while allowing the user to interact with the UI by either scrolling up, down, or selecting an image to view it in full screen. This tutorial assumes that you understand the basics of iOS development, and have worked with either UICollectionViewController or UITableViewController before but no prior networking or concurrency knowledge is required.
In this tutorial we will learn how to:
- Offload the image fetching from the Main UI thread to make the User Inferface responsive
- Avoid a common scenario when the wrong images are displayed in the cells after a scroll due to reusable cells
- Cache the images so that we don’t re-download them next time the cells become visible
- Only download images for visible cells. When the cell becomes invisible, stop the download to save bandwidth for the newly visible cells
- If the image download was stoped due to the cell becoming invisible, save the download progress so that it can be resumed next time it becomes visible again