Re: How to avoid warning?
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