"respondsToSelector" problem?

82 views
Skip to first unread message

Craig Heilman

unread,
Jul 31, 2009, 8:57:28 AM7/31/09
to madison-coco...@googlegroups.com
Hi all,

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/

Peter Rebholz

unread,
Jul 31, 2009, 9:16:34 AM7/31/09
to madison-coco...@googlegroups.com
It may because you have a colon after the lowercaseString @selector
declaration. The colon indicates there is a parameter, but
lowercaseString takes none.

Craig Heilman

unread,
Jul 31, 2009, 9:29:02 AM7/31/09
to madison-coco...@googlegroups.com
That's it! Guess one shouldn't always believe the class notes...

Craig
Reply all
Reply to author
Forward
0 new messages