On Apr 17, 2011, at 11:42 AM, WT wrote: > Hi Ken, > > On Apr 17, 2011, at 3:00 AM, Ken Thomases wrote: > >> On Apr 17, 2011, at 12:20 AM, WT wrote: >> >>> On Apr 17, 2011, at 12:31 AM, Kyle Sluder wrote: >>> >>>>> [[[[self class] alloc] init] autorelease]; >>>> >>>> You are in a class method. self == [self class], so no need to call +class >>>> here. >>> >>> What if I'm trying to subclass this singleton? >> >> What about it? 'self' identifies the actual, dynamic object receiving the >> message -- in this case, a class. It is not of the static type of the >> @implementation block it occurs within. Put another way, [self class] is no >> more dynamic than [self alloc]. > > Tell that to Erik Buck and Donald Yacktman, the authors of 'Cocoa Design > Patterns'. They explicitly assert on the second paragraph of page 151 that > [self class] is used instead of self to support instantiating the appropriate > subclass. Clearly there is some confusion regarding this matter, even among > people more experienced than I, so I don't feel so bad by being confused > about it too. :)
Re-read that paragraph of Cocoa Design Patterns. It differs from what you said above: "Of special note is the call to +alloc. Instead of sending it to MYGameHighScoreManager directly, we instead send it to [self class]." [[self class] alloc] is more subclass-friendly than [MyClass alloc]. That's what Cocoa Design Patterns is trying to say. [[self class] alloc] is no better than [self alloc], when inside a class method implementation. That's what Ken is trying to say. -- Greg Parker gpar...@apple.com Runtime Wrangler _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com