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: best way to compare selectors?




On May 4, 2007, at 11:41 AM, mmalc crawford wrote:


On May 2, 2007, at 3:36 PM, Ken Victor wrote:

whats the best and future proof way to compare 2 selectors?
[...]
but i'm wondering if i could safely use:
	selector1 == selector2

This is not necessarily future-proof.

mmalc

Then a lot of Apple documentation and sample code is not necessarily future-proof - pretty much every example that I've found on menu item validation is of the form "if ([item action] == @selector (someSelector:))"


A quick google search came up with a couple dozen such examples, including:

<http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/Protocols/NSMenuValidation_Protocol/Reference/ Reference.html#//apple_ref/occ/instm/NSObject/validateMenuItem:>

<http://developer.apple.com/samplecode/ToolbarSample/listing2.html> (in the validateMenuItem: routine)

<http://developer.apple.com/documentation/QuickTime/Conceptual/ QTKitProgrammingGuide/Chapter04/chapter_4_section_4.html>

<http://developer.apple.com/samplecode/ColorMatching/listing16.html>

<http://developer.apple.com/samplecode/QTKitPlayer/listing7.html>

<http://developer.apple.com/samplecode/Sketch-112/listing83.html>

<http://developer.apple.com/samplecode/glut/listing82.html>

<http://developer.apple.com/samplecode/EnhancedAudioBurn/listing4.html>

etc...

and I couldn't find a single example of using NSStringFromSelector and string comparison for comparing selectors.

I'm not arguing that it may not be future proof (one can easily imagine scenarios where it might not be), but comparing selectors via == is a very common idiom and will cause a whole lot of heart ache if it stops working as expected.



Glenn Andreas                      email@hidden
 <http://www.gandreas.com/> wicked fun!
Cardographer | the custom playing card designer


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >best way to compare selectors? (From: Ken Victor <email@hidden>)
 >Re: best way to compare selectors? (From: mmalc crawford <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.