title: Getting text value from alert box
body: <p>I'm having problems getting a text fields value from a UIAlertController. I am getting the value, but It seems to be executing my code in the wrong order. In the function below, I expect the function call to return a string, but the value is not set at the time the function returns. </p>
  
  <pre><code>@IBAction func btnSaveSession(sender: AnyObject) {
  
      //Prompt user to enter session name
  
      var sessionName: String = ""
  
      sessionName = promptUserToEnterSessionName("Save Session", message: "Please enter the name of your custom session below.");
  
      print("session Name: " + sessionName)
  
      //Save session to firebase.
  
      //redirect to create session controller.
  }
  
  func promptUserToEnterSessionName(title: String, message: String) -&gt; String{
  
      var sessionName: String = ""
  
      //1. Create the alert controller.
      let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
  
      //2. Add the text field. You can configure it however you need.
      alert.addTextFieldWithConfigurationHandler({ (textField) -&gt; Void in
          textField.text = "Enter session name."
      })
  
      //3. Grab the value from the text field, and print it when the user clicks OK.
      alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -&gt; Void in
          let textField = alert.textFields![0] as UITextField
          print("Text field: \(textField.text)")
          sessionName = textField.text!
      }))
  
      // 4. Present the alert.
      self.presentViewController(alert, animated: true, completion: nil)
  
      return sessionName
  
  }
  </code></pre>
  
  <p>If anyone is having problems understanding my question, please comment and I will do my best to explain. </p>