title: How do I pull this value out of a closure to update a cutom Object in Swift?
body: <p>I am building am application with a Firestore back end, and I am trying to call a document down with the current user's info for their settings page. I am able to do this no problems when updating an empty array, but am having a terrible time trying to populate a single document. I have a custom object called <code>DxUser</code>:</p>
  
  <pre><code>struct DxUser {
      var email:String?
      var name:String?
      var timeStamp:Date?
      var profileImageURL:String?
      var ehr: String?
  
      var dictionary:[String:Any]? {
          return [
              "email":email,
              "name":name,
              "timeStamp":timeStamp,
              "profileImageURL":profileImageURL,
              "ehr": ehr as Any
  
          ]
      }
  }
  
  
  extension DxUser : DocumentSerializable {
      init?(dictionary: [String : Any]) {
          guard let email = dictionary["email"] as? String,
              let name = dictionary["name"] as? String,
              let timeStamp = dictionary["timeStamp"] as? Date,
              let profileImageURL = dictionary["profileImageURL"] as? String,
              let ehr = dictionary["ehr"] as? String else {return nil}
  
          self.init(email: email, name: name, timeStamp: timeStamp, profileImageURL: profileImageURL, ehr: ehr)
      }
  }
  </code></pre>
  
  <p>In the view controller, I am trying to update this variable with the current user, but I can only grab it in the closure, and it populates as nil anywhere outside the block. Here is the basic code I am using, but can anyone tell me what I am missing?</p>
  
  <pre><code>class SettingsController: UIViewController {
  
  var dxUser = DxUser()
  
  
  override func viewDidLoad() {
      super.viewDidLoad() 
      fetchUser()
  }
  
  func fetchUser() {
  
      guard let uid = Auth.auth().currentUser?.uid else {
          return
      }
  
      let userRef = db.collection("users").document(uid)
  
      userRef.getDocument { (document, error) in
          if error != nil {
              print(error as Any)
          } else {
              self.dxUser = DxUser(dictionary: (document?.data())!)!
              self.navigationItem.title = self.dxUser.name
              print (self.dxUser)
          }
      }
  }
  </code></pre>
  
  <p>Yeah, this is how I am doing it on the table view, but I didn't see anything comparable on the regular VC.          </p>
  
  <pre><code>db.collection("users").document(uid!).collection("goals").getDocuments { (snapshot, error) in
          if error != nil {
              print(error as Any)
          } else {
              //set the profile array to equal whatever I am querying below
              goalsArray = snapshot!.documents.flatMap({Goal(dictionary: $0.data())})
              DispatchQueue.main.async {
                  self.collectionView?.reloadData()
              }
          }
      }
  </code></pre>