23

for some odd reason , with swift 3, the prepare(for segue: method refuses to acknowledge the segue identifier. I have the following IBAction's connected to a couple button's on the UI:

@IBAction func goToImagesPicker(_ sender: AnyObject) {
    performSegue(withIdentifier: "showImagePicker", sender: sender)

}

@IBAction func goToNamePicker(_ sender: AnyObject) {
    performSegue(withIdentifier: "showNamePicker", sender: sender)
}

However in my prepare(for segue: method, it doesn't recognize the different segue identifier's, I know so because my console doesn't log the messages I assigned to each:

func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showImagePicker" {

            print("This is the Image Picker")

        }

        if segue.identifier == "showNamePicker"  {

            print("This is the Name Picker")

        } 
}

any suggestions? or is this just a bug?

John Durand
  • 1,934
  • 5
  • 22
  • 34
  • Replace with following code override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { print("test"); // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } – Antony Ouseph Oct 28 '16 at 06:59

1 Answers1

57

Your method isn't getting called at all because you have the wrong signature. It was changed in Xcode 8 beta 6 to:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

Note that the type of sender is Any? instead of AnyObject?. You should have had an error after upgrading Xcode which told you your method wasn't overriding any method from its superclass which should have clued you in before you deleted the override.

dan
  • 9,695
  • 1
  • 42
  • 40
  • this seems to be the solution but, i read the doc's thoroughly i never seen a change in syntax to the sender object... So i just removed the override unknowingly. nevertheless, thanks anyhow! – John Durand Sep 19 '16 at 00:32
  • 1
    as of today, I get an error without override but override is not called – quantumpotato Mar 05 '17 at 03:31