title: How to convert document to a custom object in Swift 5?
body: <p>I've been trying to convert the document retrieved from the Firebase's Cloud Firestore to a custom object in Swift 5. I'm following the documentation:</p>
  <ul>
  <li><a href="https://firebase.google.com/docs/firestore/query-data/get-data#custom_objects" rel="nofollow noreferrer">https://firebase.google.com/docs/firestore/query-data/get-data#custom_objects</a></li>
  </ul>
  <p>However, Xcode shows me the error <code>Value of type 'NSObject' has no member 'data'</code> for the line <code>try $0.data(as: JStoreUser.self)</code>. I've defined the struct as <code>Codable</code>.</p>
  <p>The code:</p>
  <pre class="lang-swift prettyprint-override"><code>func getJStoreUserFromDB() {
      db = Firestore.firestore()
      let user = Auth.auth().currentUser
      db.collection(&quot;users&quot;).document((user?.email)!).getDocument() { 
          (document, error) in
          let result = Result {
              try document.flatMap {
                  try $0.data(as: JStoreUser.self)
              }
          }
      }
  }
  </code></pre>
  <p>The user struct:</p>
  <pre class="lang-swift prettyprint-override"><code>public struct JStoreUser: Codable {
      let fullName: String
      let whatsApp: Bool
      let phoneNumber: String
      let email: String
      let creationDate: Date?
  }
  </code></pre>
  <p>The screenshot:</p>
  <p><img src="https://i.stack.imgur.com/oAeN8.png" alt="The screenshot" /></p>
  <p>Does anyone know how to resolve this?</p>