FROM : Thomas Davie
DATE : Sat Jul 08 03:28:23 2006
On 8 Jul 2006, at 02:23, Shawn Erickson wrote:
> On 7/7/06, Rob Ross <<email_removed>> wrote:
>
>> Are you saying you can write an init method with a signature like
>> this:
>>
>> - (FooClass *)init;
>>
>> I thought that if you overrode a method from a superclass, the
>> signatures must match (including the return type).
>>
>> Or am I wrong about that?
>
> Sorry should have been more clear in my wording (was thinking of
> designated initializers of various classes that I have)... you can
> specify type for say -(MyBubba*) [MyBubba initWithGump:] and the
> compiler will warn if you tried to assign it to a variable with the
> wrong type.
The problem is you then can't do the same when you subclass.
If I were to subclass MyBubba, and write this:
-(MyBubbaSub *) [MyBubbaSub initWithGump: andForrest:]
the compiler will stop throwing warnings, and instead throw errors.
Bob
DATE : Sat Jul 08 03:28:23 2006
On 8 Jul 2006, at 02:23, Shawn Erickson wrote:
> On 7/7/06, Rob Ross <<email_removed>> wrote:
>
>> Are you saying you can write an init method with a signature like
>> this:
>>
>> - (FooClass *)init;
>>
>> I thought that if you overrode a method from a superclass, the
>> signatures must match (including the return type).
>>
>> Or am I wrong about that?
>
> Sorry should have been more clear in my wording (was thinking of
> designated initializers of various classes that I have)... you can
> specify type for say -(MyBubba*) [MyBubba initWithGump:] and the
> compiler will warn if you tried to assign it to a variable with the
> wrong type.
The problem is you then can't do the same when you subclass.
If I were to subclass MyBubba, and write this:
-(MyBubbaSub *) [MyBubbaSub initWithGump: andForrest:]
the compiler will stop throwing warnings, and instead throw errors.
Bob






Cocoa mail archive

