Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Types for the method have to conform?



> In other words, instead of writing this:
> 
>      id foo = [[FooMatic alloc] initWithData ...];
> 
> Write it like this:
> 
>      FooMatic *foo = [[FooMatic alloc] initWithData ...];
> 
> That way the compiler knows to use the signature found in the
> FooMatic class for that method.

I don't think that will help (although doing so is a good idea in its
own right)...

The problem in this case is that +alloc returns an id, so the compiler
can't identify the recipient of -initWithData..., regardless of what
you put on the left side of the = symbol.  What's needed is a cast:

FooMatic *foo = [(FooMatic *)[FooMatic alloc] initWithData...];

Another alternative is to redeclare +alloc as +(FooMatic *)alloc in
your class (although this will also generate a warning), then you
wouldn't need the cast.

-- 
// jack
// http://www.nuthole.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Types for the method have to conform? (From: John Calsbeek <email@hidden>)
 >Re: Types for the method have to conform? (From: Sherm Pendley <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.