Passing data with Unwind Segue in Swift Language – iOS 8

Unwind Segue Data
Unwind Segue Data

We have learn about Work with Unwind Segue in Swift Language – iOS 8 in first tutorial. Now we will learn how to pass the data with unwind segue.

It just simple.

Continue with the same example project.

Take data variables which you want to get in the parent view.

For example,

class ViewController2: UIViewController {
    var data:String = "view 2 data"
    ....
}

To get data from first view controller we have to get data from source view controller like follows :

    @IBAction func unwindToVC(segue:UIStoryboardSegue) {
        if(segue.sourceViewController .isKindOfClass(ViewController2))
        {
            var view2:ViewController2 = segue.sourceViewController as ViewController2
            let alert = UIAlertView()
            alert.title = "UnwindSegue Data"
            alert.message = view2.data
            alert.addButtonWithTitle("Ok")
            alert.show()
        }
        if(segue.sourceViewController .isKindOfClass(ViewController3))
        {
            var view3:ViewController3 = segue.sourceViewController as ViewController3
            let alert = UIAlertView()
            alert.title = "UnwindSegue Data"
            alert.message = view3.data
            alert.addButtonWithTitle("Ok")
            alert.show()
        }
    }

Download project with this stuff UnwindSegueData.zip

Thanks!

Happy Coding 😀