title: Firestore- Showing data in Tableview
body: <p>I am attempting to show my Firestore data into my Tableview but I can't seem to get it to show up. </p>
  
  <pre><code>protocol DocumentSerializeable {
      init?(dictionary:[String:Any])
  }
  
  struct Sourse {
      var name: String
      var content: String
      var timeStamp: Date
  
      var dictionary: [String: Any] {
          return [
              "name": name,
              "content": content,
              "timestamp": timeStamp
          ]
      }
  }
  
  
  extension Sourse : DocumentSerializeable {
      init?(dictionary: [String : Any]) {
          guard let name = dictionary["name"] as? String,
              let content = dictionary["content"] as? String,
              let timeStamp = dictionary["timeStamp"] as? Date else {return nil}
  
          self.init(name: name, content: content, timeStamp: timeStamp)
  
      }
  }
  
  class SourseListTableViewController: UITableViewController {
  
      var db: Firestore!
  
      var sourseArray = [Sourse]()
  
      private var document: [DocumentSnapshot] = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.tableView.delegate = self
          self.tableView.dataSource = self
  
          //initalize Database
          db = Firestore.firestore()
          loadData()
  
      }
  </code></pre>
  
  <p>At first I tried this code below, there were no errors but nothing loaded in the tableview. </p>
  
  <pre><code>func loadData() {
      db.collection("sourses").getDocuments() {
          snapshot, error in
          if let error = error {
              print("\(error.localizedDescription)")
          } else {
              self.sourseArray = snapshot!.documents.flatMap({Sourse(dictionary: $0.data())})
              DispatchQueue.main.async {
                  self.tableView.reloadData()
              }
          }
      }
  }
  </code></pre>
  
  <p>After some research (reading from <a href="https://stackoverflow.com/questions/50191787/firestore-append-to-tableview-when-view-is-loaded">Firestore - Append to tableView when view is loaded</a> )  I tried this code below, but I get the error "Cannot convert value of type '(name: String, content: String, timeStamp: Date?)' to expected argument type 'Sourse'" So I tried it with the date removed from all the code and I still couldn't get it to work.</p>
  
  <pre><code>func loadData() {
          db.collection("sourses").getDocuments() {
              snapshot, error in
              if let error = error {
                  print("\(error.localizedDescription)")
              } else {
                  for document in snapshot!.documents {
  
                      let data = document.data()
                      let name = data["name"] as? String ?? ""
                      let content = data["content"] as? String ?? ""
                      let timeStamp = data["timeStamp"] as? Date 
  
                      let newSourse = (name:name, content:content, timeStamp: timeStamp)
                      self.sourseArray.append(newSourse)
                  }
              }
          }
      }
  </code></pre>
  
  <p>Here is my numberOfRows/CellForRow to make sure its not the tableview itself. I've also double checked the "cell identifier" with my storyboard.</p>
  
  <pre><code>override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          // #warning Incomplete implementation, return the number of rows
          return sourseArray.count
      }
  
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "SourseTableViewCell", for: indexPath)
  
          let sourse = sourseArray[indexPath.row]
  
          cell.textLabel?.text = "\(sourse.name)"
          cell.detailTextLabel?.text = "\(sourse.content)"
  
          return cell
      }
  </code></pre>