I'm getting an error when trying to create a custom Class for my iOS Swift application:
Super.init called before returning from initializer
and
Will never be executed
Here is my code:
class CardTableViewCell: UITableViewCell {
//Vars
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var thumbImage: UIImageView!
@IBOutlet weak var detailsLabel: UILabel!
@IBOutlet weak var costLabel: UILabel!
init(name: String){
self.nameLabel.text = name
} //<-- Error here
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
super.init(coder:aDecoder) //<--- Error Here
}
}
What am I doing wrong here? I've never had to add the init Coder method to a custom class before.
I've partially fixed the code, see below.
Updated Code: class CardTableViewCell: UITableViewCell {
//Vars
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var thumbImage: UIImageView!
@IBOutlet weak var detailsLabel: UILabel!
@IBOutlet weak var costLabel: UILabel!
init(name: String, subtitle: String) {
super.init(style: UITableViewCellStyle.Default, reuseIdentifier: name)
self.nameLabel.text = name
self.subtitleLabel.text = subtitle
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
var lers = CardTableViewCell(name: "Happy", subtitle: "Gilmore") //<-- ERROR HERE
print(lers.subtitleLabel.text)
Error is returning:
Execution was interupted, reason EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
I don't understand the how, what, or why for the init code. If someone can point me to some proper documentation on Swift 2, please show me. All of apples development documents are dreadful.