On Mar 11, 2013, at 1:33 PM, Dave <d...@looktowindward.com> wrote:
> On 11 Mar 2013, at 20:26, Mike Abdullah wrote:
>>> 
>>> I had assumed (and I thought I'd done something like this before) that the:
>>> 
>>> myDict = [[super class] newDict];
>>> 
>>> statement would call newDict in BaseClass???? Instead it calls the version 
>>> in NewClass and goes into an infinite loop!!
>> 
>> Yes. [super class] calls super's implementation of the -class method. You 
>> haven't overridden -class, so it does the same thing as [self class].
>> 
>> People often make the same mistake in trying to do [super respondsToSelector…
>> 
>> I'm guessing what you're really after is [[self superclass] newDict]
>> 
> 
> Thanks a Million, yes that's what I wanted!

Are you sure?  This will indeed call the superclass's 'newDict', but the 'self' 
object will be the superclass, not your class.  That means it'll (almost 
certainly) create an instance of your class's superclass.  The easier way to do 
this is just [Foo newDict], where Foo is the name of your superclass.

If you want to invoke your superclass method, but with your class as 'self' — 
i.e. if you want to create an instance of your class — you should use [super 
newDict].

> There isn't a
> 
> -newDict
> 
> method defined, so how come I didn't get a complier error?

[super class] returns Class, which works kindof like 'id' for purposes of 
looking up methods, except only looking at class methods (and instance methods 
from the root class).

John.
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to