Search code examples
swiftcastingsegue

Problem with cast on the function prepareForSegue


I have an error with my segue. When I click on the information button the application crashes. In the title View I have multiple segues. The first one is for send array to the register view and the others is for opening my information Pop Up.

The message error is:

showing error message

And this is the main StoryBoard:

main Storyboard

How do I fix this?


Solution

  • If you have 2 segues then you need to differentiate them with the identifier

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
       if segue.identifer == "toPopUp" {
          if let yourVC = segue.destination as? YourPopController {
            // set data
          }
       }
       else {
          if let yourVC = segue.destination as? RegisterViewController {
             // set data
          }
       } 
    }