Swift: prepareForSegue with two different segues

Take out your IBActions (making sure to delete them in the Connections Inspector via the right side bar in the Interface Builder as well as in your code). For the segues, just use the Interface Builder, make sure both segue's identifiers are correct, then try this prepareForSegue method:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "matchSegue" {
        let controller = segue.destinationViewController as! ResultViewController
        controller.match = self.match
    } else if segue.identifier == "historySegue" {
        let controller = segue.destinationViewController as! HistoryViewController
        controller.history = self.history
    }
}

You could switch it...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if let identifier = segue.identifier {
        switch identifier {
        case "matchSegue":
            let controller = segue.destinationViewController as! ResultViewController
            controller.match = self.match
        case "historySegue":
            let controller = segue.destinationViewController as! HistoryViewController
            controller.history = self.history
        }
    }
}

Tags:

Xcode

Swift

Segue