On Dec 29, 2008, at 22:06, Steve Cronin wrote:

In the meantime, tweaked your snippet and just added this at the end of the header of the class where the -respondsToSelector: issue arose:

//respondsToSelector silencer - see -myMethodName
@interface NSObject (MyClassName)
- (id) foo;
@end

This silences the compiler without any #import being required in the .m file AND allows me to document to issue in the header where it seems to me it belongs. YAY!! Any downsides to this?

In effect, you're declaring an informal protocol. Why not use a real protocol (perhaps one whose methods are all optional) in its own header file?

The various classes that implement these methods can #import and adopt the protocol (so documenting what's going on).

The method that tests the selectors can use an object of type id<yourProtocol> instead of plain id (so documenting what's going on) and the compiler will stop complaining without resorting to trickery.

The advantage of this approach is that you don't have to add explanations to your header files. The protocol is self-documenting, and describes what's *actually* going on in your design.


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to