prepare(for:sender:) not getting called
Asked Answered
P

1

6

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.

Premillenarian answered 15/8, 2016 at 20:43 Comment(2)
Did you try "Edit -> Convert -> To Latest Swift Syntax ..." ?Appressed
It's already a Swift 3 project, just not the very latest version of Swift 3.Premillenarian
L
10

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"

Loricate answered 15/8, 2016 at 20:49 Comment(1)
Just discovered that myself. Also for whatever reason it's not showing up in autocomplete.Premillenarian

© 2022 - 2024 — McMap. All rights reserved.