• 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: How to avoid warning?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to avoid warning?


  • Subject: Re: How to avoid warning?
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 22 Jan 2013 11:12:01 -0800

On Jan 22, 2013, at 9:23 AM, Dave <email@hidden> wrote:

>> You could try declaring initWithManager: in a category on the class visible only to your implementation code. (i.e. at the top of your .m file)
>
> The class name is passed in as a string and the class is formed from that, so I can't pre-declare it. Please see my other reply.

Sure you can:

@interface SomeFictionalClassName
- (id) initWithManager: (Foo*)manager;
@end

Put that at the top of your source file and the warning will go away, because the compiler is now confident that there exists an -initWithManager: method. (The fact that you’ve declared it on a completely fictional class doesn’t matter.)

As others have said, though, it really sounds like what you want is a protocol that defines the -initWithManager: method. This is a better solution because it adds more type-safety — if you ever rename -initWithManager:, but don’t fix all the places it’s used, the compiler will then be able to complain about the places you missed, so you’ll avoid confusing runtime errors.

—Jens
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How to avoid warning?
      • From: Uli Kusterer <email@hidden>
References: 
 >How to avoid warning? (From: Dave <email@hidden>)
 >Re: How to avoid warning? (From: Steve Sisak <email@hidden>)
 >Re: How to avoid warning? (From: Dave <email@hidden>)

  • Prev by Date: object.struct.element as lvalue
  • Next by Date: Re: How to avoid warning?
  • Previous by thread: Re: How to avoid warning?
  • Next by thread: Re: How to avoid warning?
  • Index(es):
    • Date
    • Thread