Actually there is an answer without hardcoded code. In your storyboard, you can control the drag and drop of a button onto the next view controller and define segue there. This ensures that whenever you press a button, a segue will be called. You can see this in the "Connection Inspector" button when the sessions are running.
If you want to put data in the destination view controller, you can add inaction to the button and put the data in preparation for the segue function. The nice thing about this is that your triggers will still start from your button. This part will look like this:
@IBAction func buttonPressed(_ sender: UIButton) { someImportantData = "some data if needed" //no need to trigger segue :) } //not your case, but in order to understand the sage of this approach @IBAction func button2Pressed(_ sender: UIButton) { someImportantData = "some data2 if needed" //no need to trigger segue :) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { //retrieve the destination view controller for free if let myDestincationViewController = (segue.destination as? MyDestincationViewController) { myDestincationViewController.someImportantData = someImportantData } }
This way you do not need hardcoded strings for segue identifiers, for storyboard identifiers, etc., and you can even prepare your destination view manager if necessary.
source share