I am a little new to the concept of custom initializers, so itβs hard for me to figure out if what I am trying to do is possible.
I am using the source code to create a messaging application. All the code was written without using the storyboards that I would now like to implement.
The initialization, as implemented in the source code, is as follows:
init(chat: Chat) {
self.chat = chat
super.init(nibName: nil, bundle: nil)
title = chat.user.name
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
In the method, the didSelectRowAtIndexPathsource code passed its own initialization parameter as follows:
let chat = chats[indexPath.row]
let chatViewController = MessagesViewController(chat: chat)
navigationController?.pushViewController(chatViewController, animated: true)
What I tried to do was just create a UIViewController storyboard by setting the class to the source code, i.e. by setting the ViewController storyboard in: MessagesViewController and then running segue. Like this:
if segue.identifier == "ToMessages" {
var messagesViewController: MessagesViewController = segue.destinationViewController as MessagesViewController
let chat = chats[indexPath.row]
messagesViewController.chat = chat
}
Then performSegueWithIdentifier("ToMessages", sender: self)
When I do this, I get this fatal error: fatal error: init(coder:) has not been implemented:
, , chat. , , , , , , , .
, , , prepareForSegue, :
var destinationVC = segue.destinationViewController as MessagesViewController(chat: chat)