Q: Designated initializers: what are they?
Q: Designated initializers: what are they?
- Subject: Q: Designated initializers: what are they?
- From: email@hidden
- Date: Sat, 12 May 2001 00:45:00 -0700
I've just spent way too much trying to debug a problem which is probably
due to my lack of fundamental understanding of Cocoa, so I'm seeking
enlightenment.
I wrote a custom NSView for which I wanted to implement drag and drop.
It failed to receive drops because it turned out that the object never
received the registerForDraggedTypes: message I was sending it from my
initWithFrame: method, because this method was never called. Instead
initWithCoder: was called, which I did not think to implement.
Now, the reason for my confusion is that initWithFrame: is supposed to
be the "designated initializer" for the NSView class. Doesn't that mean
that that's the one method that's always going to be called eventually,
no matter what other initializers get called? Since that's (apparently)
not the case, what does it mean to be a "designated initializer"? And am
I supposed to duplicate my initialization code in every possible
initializer, i.e. initWithFrame: and initWithCode:, or is there a more
elegant solution?
Arno.
PS: anybody at Apple had a look at the problems with NSTextView I posted
about earlier this week. Ali? Chuck? Andrew? Anyone?