I'm working through the Favorite Athlete Lab in the Develop in Swift Data Collections book.
The guide says:
In the addAthlete method, instantiate and return a new instance of AthleteFormViewController.
When I control-dray to create the IBActionSegue, I am given the code:
@IBSegueAction func addAthlete(_ coder: NSCoder) -> AthleteFormViewController? {
return <#AthleteFormViewController(coder: coder)#>
}
I'm not sure what I should add but I currently have:
@IBSegueAction func addAthlete(_ coder: NSCoder) -> AthleteFormViewController? {
let newViewController = AthleteFormViewController(coder: coder)
return newViewController
}
When I run the app and click the button connected to the Segue Action, the required init on the View Controller gives the error:
Fatal error: init(coder:) has not been implemented
I dont know if the way I instantiate and return AthleteFormViewController is the issue, but it seems to be where it goes wrong and where I dont understand quite what is required.
Update: Got it working. The problem did not seem to be the way I created and returned the instance, but the auto-added required init on the target View Controller.
Xcode's fix supplied:
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
But I had to change this to:
required init?(coder: NSCoder) {
super.init(coder: coder)
}
What I'm trying to work out now is if I should have known this already? I did not.