While working through assignment 1, section 4 of CS193P (Stanford
iPhone App Programming), I'm having a problem getting
"respondsToSelector" to work. It's probably something really stupid
but I don't understand why it's not working. I'm using the example
code given in the handout almost word for word. Here's what I've got:
NSMutableArray *myArray = [NSArray arrayWithObjects: @"String 1",
@"String 2", [NSURL ...], other objects, nil];
SEL sel = @selector(lowercaseString:);
for( id *anItem in myArray )
{
... do some isMemberOfClass & isKindOfClass queries (works fine) ...
if( [NSObject *)anItem respondsToSelector:sel] )
{
*** THIS NEVER GETS EXECUTED - even for the NSString array elements!
***
NSLog( @"Responds to lowercaseString: YES" );
NSLog( [NSString stringWithFormat:@"lowercaseString is: %@",
[(NSObject *)anItem performSelector:sel]] );
}
else
{
NSLog( @"Responds to lowercaseString: NO" );
}
}
Anyone see what I'm doing wrong here?
Thanks,
Craig
--
Craig Heilman
Bugaboo Software - Software Engineering & Consulting
http://www.bugsoft.com/