title: wait for response Alamofire swift
body: <p>I need to wait for response.response?.allHeaderFields data before executing function. I've searched the net and didn't quite get how to add "completion handler" to alamofire request. Or if there are any other ways to make the function wait.    </p>
  
  <pre><code>@IBAction func comfirmation(sender: UIButton) {
      if CodeTextField.text != "" {
          print("in comfirmation function")
          let comfirmationRequestData = [
              "phone" : "\(appDelegate.savedNumber)",
              "code" : "\(CodeTextField.text!)"
          ]
          Alamofire.request(.POST,
              "http://192.168.214.241:4000/login",
              parameters: comfirmationRequestData,
              encoding: .JSON).responseJSON {
                  response in
                  switch response.result {
                  case .Success:
                      let jsonDecrypted = JSON(response.result.value!)
                      print(jsonDecrypted)
                      let headerFile = response.response?.allHeaderFields as? [String:String]
                      print(headerFile)
  
                  case .Failure(let error):
                      print(error)
                  }
          }
          print("in comfirmation function. success")
          appDelegate.defaults.setValue(appDelegate.savedNumber, forKey: "phoneNumber")
      } else {
          print("in comfirmation function. failed")
      }
  
  }
  </code></pre>