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 😀