Re: Class responds to selector?
Re: Class responds to selector?
- Subject: Re: Class responds to selector?
- From: Sherm Pendley <email@hidden>
- Date: Mon, 25 Jul 2005 07:44:31 -0400
On Jul 25, 2005, at 7:14 AM, Theodore H. Smith wrote:
OK, so I can use respondsToSelector: to ask if an object responds
to a selector.
But what about telling if a class responds to a selector?
This code here:
if ( ! [NSColor instancesRespondToSelector: @selector
(controlAlternatingRowBackgroundColors) ] ) {
return [NSColor whiteColor];
}
returns false when actually NSColor the class does actually respond
to controlAlternatingRowBackgroundColors.
Of course it returns false - you're asking it if *instances* of
NSColor respond to that message, not if the class itself responds to it.
The solution is in the first line of your own message - send -
respondsToSelector: to the class, instead of to an instance of the
class. This works because a Class object can also receive instance
messages that are defined in the root class:
if (![NSColor respondsToSelector:@selector
(controlAlternatingRowBackgroundColors)]) {
return [NSColor whiteColor];
}
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden