Apple defines a segue as a transition between two view controllers. An unwinding segue – or exit segue – dismisses a view controller. For example, when you click ‘Cancel’, you go back to the original view controller.
Let’s start:
We have two view controllers with a single button on each one, and a segue between the two. When you press ‘Go to Second VC’, it will show the Unwind View Controller’. The goal is to click the ‘Unwind’ button and unwind that view controller.
Within the main view controller, you will need to create an IBAction function that has a UIStoryboard segue. The method name can be called whatever you please. By doing this, it tells Xcode that this function can serve as an unwind method.
Now in the Unwind View Controller, you’ll want to control-drag from the Unwind button to the Exit icon. It will now display the unwind method you just created:
Select the function to use. Build and run, you should now have a functioning unwind segue.