title: Swift - Two Firestore listeners on same screen not working
body: <p>I am trying to download two data from two collections in Firestore using Listeners. However I one retrieves the data correctly from one collection however the other does not. I tried setting up two separate listeners however still no data is being retrieved. I am not sure if it is possible to have two listeners but I assumed it would be as there would be occasions where multiple collections would have to be retrieved.</p>
  <pre><code>   func getConnections() {
          self.cListener = FirebaseReference(.Connection).addSnapshotListener({ snapshot, err in
              if let error = err {
                  debugPrint(error.localizedDescription)
                  return
              }
              
              snapshot?.documentChanges.forEach({ change in
                  let data = change.document.data()
                  let connection = Connection.init(data: data)
                  switch change.type {
                  case .added:
                      self.onCDocumentAdded(change: change, connection: connection)
                  case .modified:
                      self.onCDocumentModified(change: change, connection: connection)
                  case .removed:
                      self.onCDocumentRemoved(change: change)
                  }
              })
          })
      }
      
      //MARK:Functions
      func onCDocumentAdded(change: DocumentChange, connection: Connection) {
          let newIndex = Int(change.newIndex)
          connections.insert(connection, at: newIndex)
      }
      
      func onCDocumentModified(change: DocumentChange, connection: Connection) {
          if change.newIndex == change.oldIndex {
              
              // Row modified but stayed in same position
              let index = Int(change.newIndex)
              connections[index] = connection
          } else {
              
              // Row changed and moved position
              let oldIndex = Int(change.oldIndex)
              let newIndex = Int(change.newIndex)
              connections.remove(at: oldIndex)
              connections.insert(connection, at: newIndex)
          }
      }
      
      func onCDocumentRemoved(change: DocumentChange) {
          let oldIndex = Int(change.oldIndex)
          connections.remove(at: oldIndex)
      }
      
      func getUsers() {
                 self.listener = FirebaseReference(.User).addSnapshotListener({ snapshot, error in
                 if let error = error {
                     debugPrint(error.localizedDescription)
                     return
                 }
                 
                 snapshot?.documentChanges.forEach({ (change) in
                     let data = change.document.data()
                     let user = User.init(data: data)
                     
                     switch change.type {
                     case .added:
                         self.onDocumentAdded(change: change, user: user)
                     case .modified:
                         self.onDocumentModified(change: change, user: user)
                     case .removed:
                         self.onDocumentRemoved(change: change)
                     }
                 })
             })
             }
      
         //MARK:Functions
         func onDocumentAdded(change: DocumentChange, user: User) {
             let newIndex = Int(change.newIndex)
             users.insert(user, at: newIndex)
             searchResultTV.insertRows(at: [IndexPath(item: newIndex, section: 0)], with: .automatic)
         }
         
         func onDocumentModified(change: DocumentChange, user: User) {
             if change.newIndex == change.oldIndex {
                 
                 // Row modified but stayed in same position
                 let index = Int(change.newIndex)
                 users[index] = user
                 //setupDetails()
                 searchResultTV.reloadRows(at: [IndexPath(item: index, section: 0)], with: .automatic)
             } else {
                 
                 // Row changed and moved position
                 let oldIndex = Int(change.oldIndex)
                 let newIndex = Int(change.newIndex)
                 users.remove(at: oldIndex)
                 users.insert(user, at: newIndex)
                 searchResultTV.moveRow(at: IndexPath(item: oldIndex, section: 0), to: IndexPath(item: newIndex, section: 0))
             }
         }
         
         func onDocumentRemoved(change: DocumentChange) {
             let oldIndex = Int(change.oldIndex)
             users.remove(at: oldIndex)
             searchResultTV.deleteRows(at: [IndexPath(item: oldIndex, section: 0)], with: .automatic)
         }
      
  </code></pre>