1

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.

Xcoder
  • 1,433
  • 3
  • 17
  • 37
  • 2
    You can ignore a segue by implementing `override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { if identifier == "aSegueIWantToDisable" { return false }; return true }` – vacawama Dec 06 '17 at 01:02

1 Answers1

1

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 
}
Diogo Souza
  • 370
  • 2
  • 12
  • Thank you for your answer. If it is not possible, is there a workaround? – Xcoder Dec 06 '17 at 01:06
  • Maybe there is! Could you explain a little more what you are trying to achieve so that I can think of a solution? – Diogo Souza Dec 06 '17 at 01:08
  • I added a workaround if you just want to avoid the segue to happen. I noticed that vacawama commented it earlier, so I used his code. – Diogo Souza Dec 06 '17 at 01:17