Joseph Astrahan Joseph Astrahan - 2 months ago 23
Swift Question

Swift 2 to 3 Migration for prepareForSegue

This question might have been answered already but I could not find it.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
}


This code worked fine in swift 2 but now gives me an error to remove the override.

Exact Error: "Method does not override any method from its superclass"

What is the new correct method for swift 3 for this? I can't seem to find any documentation on it anywhere.

Answer

Method signature is changed in swift 3.0

Replace this

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

With

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