D. Murphy D. Murphy - 1 year ago 134
iOS Question

Printing Variable Unwind Segue - Xcode 8.0 Swift 3.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



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.


Answer Source

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")

        let textContents = testTextField.text

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download