title: What is the proper way to read values from Firebase considering the MVC approach?
body: <p>I'm quite new to Swift and currently dealing with the Firebase-Database.
  I managed to realise the functions that I want to have, but my implementation feels not right.
  Most I am struggling with the closures, that I need to get data from Firebase.</p>
  <p>I tried to follow the MVC approach and have DataBaseManager, which is getting filling my model:</p>
  <pre><code>func getCollectionData(user: String, callback: @escaping([CollectionData]) -&gt; Void) {
          
          var dataArray: [CollectionData] = []
          var imageArray:[String] = []
          let db = Firestore.firestore()
  
          db.collection(user).getDocuments() { (QuerySnapshot, err) in
              if let err = err {
                  print(&quot;Error getting documents : \(err)&quot;)
              }
              
              else {
                  for document in QuerySnapshot!.documents {
                      let album = document.get(&quot;album&quot;) as! String
                      let artist = document.get(&quot;artist&quot;) as! String
                      let genre = document.get(&quot;genre&quot;) as! String
                      let location = document.get(&quot;location&quot;) as! String
                      var a = CollectionData(album: album, artist: artist, imageArray: imageArray, genre: genre, location: location)
                      a.imageArray!.append(document.get(&quot;fronturl&quot;) as? String ?? &quot;No Image&quot;)
                      a.imageArray!.append(document.get(&quot;backurl&quot;) as? String ?? &quot;No Image&quot;)
                      a.imageArray!.append(document.get(&quot;coverlurl&quot;) as? String ?? &quot;No Image&quot;)
                      
                      dataArray.append(a)
    
                  }
                  
                  callback(dataArray)
                  
              }
          }
      }
  </code></pre>
  <p>With this I'm getting the information and the downloadlinks, which I later use in a gallery.
  Is this the right way?
  I feel not, because the fiddling starts, when I fetch the data from my ViewController:</p>
  <pre><code>var dataArray = []
          dataBaseManager.getCollectionData(user: user) { data in
              self.dataArray = data
  
  </code></pre>
  <p>I can see, that I sometimes run into problems with timing, when I use data from dataArray immediately after running the closure.</p>
  <p>My question is, this a valid way to handle the data from Firebase or is there a more elegant way to achieve this?</p>