Search code examples
swiftstoryboarduistoryboardsegue

How to get rid of or change a storyboard created segue programatically


I have a segue from one view controller to another, which was created in the storyboard of my project. I'm wondering if there is a way to change or get rid of that segue through code. Thanks, using Xcode 9 Swift 4.


Solution

  • Apparently it's not possible... look at the answer on this post. And the documentation says this about creating segues:

    "You do not create segue objects directly. Instead, the storyboard runtime creates them when it must perform a segue between two view controllers."

    Although it's not about changing or deleting the segue, I think it's the same logic.

    If you just want to avoid the segue to happen you can do that inside "shouldPerformSegue" (like vacawama said in the comments):

    override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { 
        if identifier == "aSegueIWantToDisable" { 
            return false 
        } 
        return true 
    }