On Oct 30, 2010, at 12:12, Dave Carrigan wrote:
> All initialized objects have at some point called super; they aren't fully
> initialized otherwise. In the implementation, the non-designated initializers
> typically chain to the designated initializer, which in turn chains to
> super's (usually designated) initializer. So just because a designated
> initializer didn't call super's designated initializer, it doesn't mean that
> super's designated initialer was not invoked; it was.
I was going to post much the same answer, but the documentation pointed out a
complication:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html%23//apple_ref/doc/uid/TP30001163-CH22-SW1
If you override designated initializer A, then call super's non-designated
initializer B, then B will call A, causing a recursion.
What the documentation generally describes, I believe, is a safe set of
guidelines to follow when subclasses override *designated* initializers. That
was not the case in the Hillegass case, which is why that pattern was safe in
the given scenario.
I don't believe there's any secret sauce in the designated initializer pattern
that Apple's documentation rules depend on. I believe that common sense applies
here -- any pattern that gets precisely *one* designated initializer invoked in
*every* class up the inheritance chain is both viable and legal. When you
follow the rules, it's reliably correct. When you go outside the rules, you
have to establish the correctness separately.
[I'll also add that there are classes with multiple designated initializers.
It's not really relevant to this question, but it's worth keeping in mind.]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]