On Jan 23, 2013, at 8:22 AM, Uli Kusterer <witness.of.teacht...@gmx.net> 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com