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,
[code language=”obj-c”]
class ViewController2: UIViewController {
var data:String = "view 2 data"
….
}
[/code]

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

[code language=”obj-c”]
@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()
}
}
[/code]
Download project with this stuff UnwindSegueData.zip
Thanks!
Happy Coding 😀

Work with Unwind Segue in Swift Language – iOS 8

Unwind - Exit
Unwind – Exit

An unwind segue (sometimes called exit segue) can be used to navigate back through push, modal or popover segues (as if you popped the navigation item from the navigation bar, closed the popover or dismissed the modally presented view controller). On top of that you can actually unwind through not only one but a series of push/modal/popover segues, e.g. “go back” multiple steps in your navigation hierarchy with a single unwind action.

To enable the Unwind Segue you need to add some code first.
[code language=”obj-c”]
@IBAction func unwindToVC(segue: UIStoryboardSegue) {
}
[/code]
You have to add this code in the view controller where you want to unwind (came back).

Unwind To View
Unwind To View

Suppose you want to came back from second or third view to first view then you have to add the code in first view.
Then just connect any control(Which contains action) with the unwind segue.
Unwind Segue
Unwind Segue

For check the particular view controller by unwind segue, use following code :
[code language=”obj-c”]
@IBAction func unwindToVC(segue:UIStoryboardSegue) {
if(segue.sourceViewController .isKindOfClass(ViewController2))
{
let alert = UIAlertView()
alert.title = "UnwindSegue"
alert.message = "Unwind from view 2"
alert.addButtonWithTitle("Ok")
alert.show()
}
if(segue.sourceViewController .isKindOfClass(ViewController3))
{
let alert = UIAlertView()
alert.title = "UnwindSegue"
alert.message = "Unwind from view 3"
alert.addButtonWithTitle("Ok")
alert.show()
}
}
[/code]
Download project with this stuff UnwindSegue.zip
In next tutorial you will find the topic Passing data with Unwind Segue in Swift Language – iOS 8
Thanks!
Happy Coding 😀