Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepare(for:sender:) not getting called

I downloaded Apple's MyLife sample project and attempted to build and run it using Xcode 8 beta 6.

There are two places where a view controller has implemented the prepare(for:sender:) call to do stuff before a storyboard segue is performed.

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

That line has an error saying "Method does not override any method from its superclass".

If I remove the override, the app builds but the method isn't called when it should be.

like image 670
Frank Schmitt Avatar asked Aug 15 '16 20:08

Frank Schmitt


People also ask

What is an unwind segue?

Unlike the segues that you use to present view controllers, an unwind segue promises the dismissal of the current view controller without promising a specific target for the resulting transition. Instead, UIKit determines the target of an unwind segue programmatically at runtime.

What is the significance of the method prepare for sender :)?

prepare(for:sender:)Notifies the view controller that a segue is about to be performed.

What is Uistoryboardsegue?

An object that prepares for and performs the visual transition between two view controllers.


1 Answers

The method signature has changed. sender is now Any? instead of AnyObject?

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

This is to coincide with the changes to how Swift is bridged with obj-c, described here under "New in Xcode 8 beta 6 - Swift Compiler"

like image 95
jjatie Avatar answered Sep 21 '22 11:09

jjatie