i want to create a subclass of NSWindow
. this subclass needs to initialize some member variables before they are used. what is the best way to capture initialization in objective c? what i find is that init
rarely gets called in a way that allows me to do this. NSWindow
has a couple of initialization vectors that i would need to override. do i need to override each of them?
Each class should have one so-called designated initializer. This is the init method that all other init methods call. That's the one to override. The documentation usually tells you which one the designated initializer is. In the case of NSWindow
, it is:
initWithContentRect:styleMask:backing:defer:
This method is the designated initializer for the NSWindow class.
In addition to the designated initializer, you should also override -initWithCoder:
if the class you subclass implements the NSCoding
protocol. -initWithCoder:
is the initializer that is used when an instance is instantiated from an archive (such as a NIB file).
See The Designated Initializer in Apple's "The Objective-C Programming Language".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With