ios - Pass Custom Init Parameter through Storyboard Segue in Swift -


i'm new concept of custom initializers, i'm having hard time understanding if im trying possible.

i'm using source code create messaging app. code written without use of storyboards, i'd implement.

the init implemented in source code this:

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 didselectrowatindexpath method, original code passed custom init parameter way:

 let chat = chats[indexpath.row]     let chatviewcontroller = messagesviewcontroller(chat: chat)     navigationcontroller?.pushviewcontroller(chatviewcontroller, animated: true) 

what tried doing creating storyboard uiviewcontroller, setting class original code, is, setting storyboard viewcontroller to: messagesviewcontroller, perform segue. this:

if segue.identifier == "tomessages" {         var messagesviewcontroller: messagesviewcontroller = segue.destinationviewcontroller messagesviewcontroller         let chat = chats[indexpath.row]         messagesviewcontroller.chat = chat     } 

then performseguewithidentifier("tomessages", sender: self)

when fatal error: fatal error: init(coder:) has not been implemented:

from research , understanding of original source code, reason because not initializing chat parameter. realize may not on right track, if idea of go here appreciated.

if correct whats going on, specific question how implement parameters in prepareforsegue method, like:

var destinationvc = segue.destinationviewcontroller messagesviewcontroller(chat: chat) 

change init code follows

init(chat: chat) {     self.chat = chat     super.init()     title = chat.user.name }  required init(coder adecoder: nscoder) {     super.init(coder: adecoder) } 

init(coder:) called whenever uiviewcontroller created via storyboard. in case override called in have written fatalerror() make fail, error getting when executing.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -