• 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: Andy Lee <email@hidden>
  • Date: Wed, 23 Jan 2013 08:39:48 -0500

On Jan 23, 2013, at 8:22 AM, Uli Kusterer <email@hidden> wrote:
> @protocol UKCanInitWithManagerProtocol
> -(id)	initWithManager: (Foo*)inManager;
> @end
>
> ...
>
> if( [myClass respondsToSelector: @selector(initWithManager:)] )
> 	myObj = [(id<UKCanInitWithManagerProtocol>)[myClass alloc] initWithManager: self];
> else
> 	myObj = [[myClass alloc] init];

Well, the extra-super-defensive approach would be to not only check respondsToSelector:, but to check that the method signature of the object's implementation matches what's declared in the protocol. :)

But yeah, you can't rely on conformsToProtocol: if you don't have the luxury of making the relevant classes conform to the protocol.

--Andy

_______________________________________________

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

References: 
 >How to avoid warning? (From: Dave <email@hidden>)
 >Re: How to avoid warning? (From: Jens Alfke <email@hidden>)
 >Re: How to avoid warning? (From: Dave <email@hidden>)
 >Re: How to avoid warning? (From: Jens Alfke <email@hidden>)
 >Re: How to avoid warning? (From: Andy Lee <email@hidden>)
 >Re: How to avoid warning? (From: Charles Srstka <email@hidden>)
 >Re: How to avoid warning? (From: Andy Lee <email@hidden>)
 >Re: How to avoid warning? (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: Best guess at expressing a string as a variable
  • Next by Date: Re: Best guess at expressing a string as a variable
  • Previous by thread: Re: How to avoid warning?
  • Next by thread: [ANN] v 0.3 of MPWDrawingContext, a pleasant Objective-C drawing context updated with blocks
  • Index(es):
    • Date
    • Thread