I am trying to subclass NSTextView
and have a custom initializer.
When I add a custom initializer like below:
init(frame: NSRect, view: NSView) {
self.view = view
self.textLayer = CATextLayer()
super.init(frame: frame)
}
the compiler complains about missing init?(coder: NSCoder)
initializer and suggests the below as a fix:
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
When I apply this fix, the code compiles fine but when I run it, the app crashes giving me Fatal error: Use of unimplemented initializer 'init(frame:textContainer:)
error in the logs.
I looked at other solutions on SOF and they suggested the below:
required init?(coder: NSCoder) {
super.init(coder: coder)
}
Unfortunately, the above also doesn't fix the issue and I am getting the same crash error as before.
Any ideas what I may be doing wrong? I am using Swift 5.0. Additionally, I know there are other similar questions on SOF but their answers didn't solve my problem (maybe because of Swift's version).
Do note that removing the custom init
will fix the issue but I would like to keep the custom initializer in this case.
P.S. Swift noob here so apologies if its something trivial.