title: Activity Indicator for UICollectionView
body: <p>I have a UICollectionView that reads data from Firebase, and I want some kind of activity indicator while it's reading data.</p>
  
  <p>I want the activity indicator to start running as soon as the UICollectionView tab in the TabBar is hit, and I want it to stop and the view/uicollectionView to load once loading from Firebase is done.</p>
  
  <p>I saw this post:</p>
  
  <p><a href="https://stackoverflow.com/questions/46650183/show-activity-indicator-while-data-load-in-collectionview-swift">Show Activity Indicator while data load in collectionView Swift</a></p>
  
  <p>But I could not understand it fully because I did not know how to integrate my UICollectionView there.</p>
  
  <p>EDIT:</p>
  
  <p>This is my code that reads from Firebase: </p>
  
  <pre><code>self.ref = Database.database().reference()
              let loggedOnUserID = Auth.auth().currentUser?.uid
  
  
              if let currentUserID = loggedOnUserID
              {
                  // Retrieve the products and listen for changes
                  self.databaseHandle = self.ref?.child("Users").child(currentUserID).child("Products").observe(.childAdded, with:
                      { (snapshot) in
  
                          // Code to execute when new product is added
                          let prodValue = snapshot.value as? NSDictionary
                          let prodName = prodValue?["Name"] as? String ?? ""
                          let prodPrice = prodValue?["Price"] as? Double ?? -1
                          let prodDesc = prodValue?["Description"] as? String ?? ""
                          let prodURLS = prodValue?["MainImage"] as? String
                          let prodAmount = prodValue?["Amount"] as? Int ?? 0
                          let prodID = snapshot.key
  
                          let prodToAddToView = Product(name: prodName, price: prodPrice, currency: "NIS", description: prodDesc, location: "IL",
                                                        toSell: false, toBuy: false, owner: currentUserID, uniqueID: prodID, amount: prodAmount, mainImageURL: prodURLS)
  
  
                          self.products.append(prodToAddToView)
                          DispatchQueue.main.async
                              {
                                  self.MyProductsCollection.reloadData()
                          }
                  }
                  ) // Closes observe function
  </code></pre>