I have created a subclass of NSView as seen below
class StudentCardView: NSView {
let firstName: String
init(name: String) {
firstName = name
super.init()
}
required init?(coder: NSCoder) {
super.init(coder: coder) <-- ERROR: firstName not initialised
}
}
let myName = "Test-Name"
var cell = StudentCardView(name: myName)
How do I get rid of an error which requires firstName to be initialized in init(coder) as I don't intend to make any views of StudentCardView in the storyboard.
I agree, one is required to initialize all the constants before the superclass initializer is called. Is there a way out here? Have I made any design mistakes?