NSObject - respondsToSelector: behavior has changed under Leopard

Florent Lacheroy florent.lacheroy at alwancolor.com
Mon Dec 10 06:57:25 PST 2007


Hi all,

It seems behavior of the respondsToSelector: method of NSObject has  
changed. We have a code where the method responds "YES" under Tiger  
and "NO" under Leopard.

Please see below a little extract from our code:

- we have a "fake" NSBitmapImageRep subclass. It means it's a class  
derived from NSObject but that implements:

- (Class)class
{
	return [NSBitmapImageRep class];
}

and:

- (NSNumber *)sMaskNumber
{
	....
}


- in a NSBitmapImageRep category we have this method:

- (NSString*)sMaskNumberString
{
	NSString	*smnString = @"";
	
	if([self respondsToSelector:@selector(sMaskNumber)]) {
		NSNumber	*sMaskNumber = [self sMaskNumber];
		if( sMaskNumber) {
			....
		}
	}
	
	return smnString;
}


After putting a breakpoint in the "Class" method described above, it  
seems that now under Leopard, the respondsToSelector method is calling  
it which was not the case under Tiger.
That means the respondsToSelector is now based on the instance's class  
and not anymore on the methods implemented by the current object in  
memory?

Anyone can confirm? May be this new implementation can bring new limits?


Best Regards,




Florent Lacheroy
Software Engineer
Alwan Color Expertise



More information about the MacOSX-dev mailing list