Unwind Segues: Jump Back in the Stack
An unwind segue jumps from a deep screen to an earlier view controller without manual popping. Use it after multi-step flows to return to a root screen. If multiple screens share the same action, UIKit picks the nearest one and silently routes users wrong.
WHY IT EXISTS: Standard navigation in UIKit moves forward through push and present transitions, but going back usually means popping one level or dismissing a single modal. When a user finishes a task several screens deep, manually chaining popViewController or dismiss calls across multiple view controllers creates brittle glue code. Unwind segues let the storyboard declare a backward destination declaratively, so the framework handles the traversal.
THE MENTAL MODEL: Think of an unwind segue as a labeled emergency exit placed on an upstream view controller. Any downstream screen can pull the handle, and UIKit walks backward through the navigation stack or modal hierarchy until it finds the matching exit sign. If no sign exists, the door simply does not open.
HOW IT WORKS: You define an action method on the destination view controller using the signature func unwindActionName with a UIStoryboardSegue parameter. In Interface Builder, you connect a segue from a button or trigger in the source scene to the Exit icon, selecting that method. At runtime, UIKit searches the presented view controllers or navigation stack in reverse order, looking for the first view controller that responds to the selector. It then performs the unwind, calling prepareForSegue on the source, executing the unwind action on the destination, and removing every intermediate view controller automatically.
WHEN TO USE IT: Use unwind segues when you need to return to a specific ancestor after completing a multi-step flow, such as finishing a checkout wizard, submitting a form spread across several screens, or canceling a deep modal presentation. They keep backward navigation visible in the storyboard instead of hidden in code.
WHEN NOT TO USE IT: Avoid them in programmatic UI or coordinator-based architectures where storyboards are absent, because unwind segues require Interface Builder and segue identifiers. They also become risky when the navigation stack is dynamic or contains multiple view controllers that share the same unwind selector name; UIKit always picks the nearest match, which can route the user to an unexpected screen without warning.
ONE CANONICAL EXAMPLE: Imagine a navigation stack with Account List, then Account Detail, then Edit Account, then Confirm Changes. After the user taps Save on Confirm Changes, you want to jump directly back to Account List, skipping the intermediate screens. You implement an unwindToAccountList method on Account List, draw an unwind segue from the Save button in Confirm Changes to the Exit placeholder, and UIKit unwinds the entire stack in one transition.
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.