0

I want to print a variable when a bar button item (on the navigation bar) is pressed. When this bar button item is pressed an unwind segue will happen whilst a variable is set and then it will be printed to the console (log at the bottom of Xcode). This is my code:

    @IBAction func doneNavItem(_ sender: AnyObject) {

    textField.text = var variableUnwind

    print(variableUnwind)

}

I know that the unwind segue is being triggered before the variable can be printed from How to do something before unwind segue action? but the solutions on here do not seem to work or I might be reading it wrong.

Thanks

Community
  • 1
  • 1
D. Murphy
  • 67
  • 3
  • 11

1 Answers1

0

Please move your variable setting code to the prepare for segue method.

@IBOutlet weak var testTextField: UITextField!

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        var variableUnwind = ("StackOverFlow")

        print(variableUnwind)
        let textContents = testTextField.text
        print(textContents)

    }
Naveen Ramanathan
  • 1,876
  • 14
  • 21