title: Reassigning a value in an if statement in Swift
body: <p>the following is printing "no user with username" but is printing retVal as "false" ( I changed function to a string just for troubleshooting, ideally this should be bool )  I am new to swift and this is absolutely driving me crazy. it is making it to the chunk of code where retVal would get reassigned, but it isn't reassigning it</p>
  
  <pre><code>static func isUserNameUnique(_ username : String) -&gt; String {
  
      var retVal = "false"
  
      let db = Firestore.firestore()
      let newQuery = db.collection("users").whereField("userName", isEqualTo: username)
      newQuery.getDocuments { (document, error) in
          if document!.isEmpty {
              retVal = "true"
              print("No user with username")
          }
      }
      print("\(retVal)")
      return retVal
  }
  
  
  func validateFields() -&gt; String? {
  
      //Check that all fields are filled in
      if premierCodeTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" || userNameTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
          return "Please fill in all fields."
      }
  
      //Check unique username
      let cleanedUserName = userNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
          Utilities.isUserNameUnique(cleanedUserName) { res in
          if !res {
              // return "please choose a unique username"
          }
      }
  
      return nil
  }
  </code></pre>