iOS
Swift
Storyboard
Segue
ViewController

Storyboard Segue From View Controller to Itself

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Yes, a storyboard segue from a view controller to itself is possible. But it is important to understand what it actually does: it does not "refresh" the current instance, it creates and presents or pushes a new instance of the same scene according to the segue type.

What a self-segue really means

In Interface Builder, you can control-drag from a view controller back to the same scene and create a segue. When that segue fires, UIKit instantiates the destination scene again, even though the class is the same.

That means a self-segue is a transition from one instance of MyViewController to a second instance of MyViewController.

This distinction matters because developers often reach for a self-segue when what they really want is one of these:

  • reset the current screen state
  • update visible content in place
  • reconfigure the same controller with new data

A segue is often the wrong tool for those cases.

A working example

Suppose you want to present the same controller class modally with new input data.

swift
1import UIKit
2
3final class QuizViewController: UIViewController {
4    var questionIndex: Int = 0
5
6    @IBAction func nextQuestionTapped(_ sender: UIButton) {
7        performSegue(withIdentifier: "showNextQuestion", sender: sender)
8    }
9
10    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
11        if segue.identifier == "showNextQuestion",
12           let destination = segue.destination as? QuizViewController {
13            destination.questionIndex = questionIndex + 1
14        }
15    }
16}

If the storyboard segue points from the scene back to itself, pressing the button presents a fresh QuizViewController instance with the next question index.

When a self-segue makes sense

A self-segue can be reasonable when each screen instance is conceptually a new step even if the UI class is the same.

Examples include:

  • a wizard where each step reuses the same controller class
  • a quiz flow where each question is a fresh controller instance
  • a modal pattern where the same scene template is reused with different data

In those cases, a self-segue is just a reuse of the same scene definition.

When it is the wrong solution

If your goal is to refresh labels, clear fields, or replace the current content, creating a new controller instance is often unnecessary.

A simpler alternative may be:

  • reset your model and update the current UI
  • pop and reconfigure within a navigation stack
  • instantiate explicitly in code if storyboard wiring becomes confusing

A self-segue can accidentally grow the navigation stack or present multiple copies of the same controller, which is often not what users expect.

If the segue type is show inside a navigation controller, a self-segue usually pushes another instance of the same controller class. If the segue type is modal, it presents another one modally.

That means repeated self-segues can build deep chains of nearly identical controllers. The UI may still work, but memory usage, navigation behavior, and back-button semantics can become messy.

Explicit code is sometimes clearer

Instead of wiring a self-segue in storyboard, many teams prefer to instantiate the controller explicitly so the intent is obvious.

swift
1if let vc = storyboard?.instantiateViewController(withIdentifier: "QuizViewController") as? QuizViewController {
2    vc.questionIndex = questionIndex + 1
3    navigationController?.pushViewController(vc, animated: true)
4}

This avoids the "why is there a segue from the controller to itself?" confusion when someone else reads the storyboard later.

Common Pitfalls

A common mistake is expecting a self-segue to reset the current controller instance. It creates a new instance instead.

Another issue is accidentally stacking many copies of the same screen by repeatedly triggering the segue.

It is also easy to use a self-segue where a normal state update would be simpler and cheaper. If no real navigation is happening, you probably do not need a segue.

Summary

  • A storyboard self-segue is possible and creates a new instance of the same scene.
  • It is useful when the same controller class legitimately represents multiple navigation steps.
  • It is not the same as refreshing or resetting the current controller instance.
  • Be careful about navigation-stack growth and repeated modal presentations.
  • If the storyboard wiring feels unnatural, explicit instantiation in code is often clearer.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.