Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: respondsToSelector - #import OR compiler warnings?



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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >respondsToSelector - #import OR compiler warnings? (From: Steve Cronin <email@hidden>)
 >Re: respondsToSelector - #import OR compiler warnings? (From: Graham Cox <email@hidden>)
 >Re: respondsToSelector - #import OR compiler warnings? (From: Steve Cronin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.