• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Types for the method have to conform?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Types for the method have to conform?


  • Subject: Re: Types for the method have to conform?
  • From: Jack Nutting <email@hidden>
  • Date: Thu, 11 Aug 2005 11:10:00 +0200

> 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:

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>)

  • Prev by Date: How to make localizedStringForKey: work in a Foundation Tool?
  • Next by Date: Core Data and multiple NIBs: how to share the managedObjectContext?
  • Previous by thread: Re: Types for the method have to conform?
  • Next by thread: Class clusters and the superclass' initializer implementation
  • Index(es):
    • Date
    • Thread