Reputation: 1
I want remove (frame: )
and (coder: )
initialization from my sub class coming from my NSView super class, I tried this code but I was unable to do it, how can I make my sub just be initialized with init()
? I have to say I tried to use override
but it seems cannot help me to reach my goal of having just init()
as initialization.
class MyNSView: NSView {
convenience init() {
self.init()
}
}
Upvotes: 0
Views: 75
Reputation: 285082
No, you can't remove it.
init(frame:
is the designated initializer of NSView
As convenience
initializer you have to call it – on self
, not on super
class MyNSView: NSView {
convenience init() {
self.init(frame: .zero)
}
}
However if the view is designed in Interface Builder then init(coder
will be called.
Upvotes: 1
Reputation: 45
Try using required
keyword while implementing the init()
method.
class MyNSView: NSView {
required init() {
super.init(frame: .zero)
}
}
You'll be able to initialize instances of your class by simply using
let myView = MyNSView()
Upvotes: 0