views:

99

answers:

2

Hi, I'm having some problems working with NSStrings in Objective C... the code below returns a warning, saying:

"'NSString' may not respond to '-stringByReplacingOccurancesOfString:withString:"

NSString* NewWord = [Word stringByReplacingOccurancesOfString:@"!" 
                                                   withString:@""];

What am I doing wrong? Any help is greatly appreciated - thanks

+6  A: 

It's a spelling error. The method name is actually stringByReplacingOccurrencesOfString.

Jacob Relkin
*Facepalm* Haha thanks very much I didn't notice that
Karl Taylor
A: 

I find that the LLVM complier provides a better warning in this case:

warning: method '-stringByReplacingOccurancesOfString:withString:' not found (return type defaults to 'id')

Michael Dunstan
I don't think it's really that much better; a *really* good message would suggest an existing method name to the user, if it "detects" a possible typo.
Shaggy Frog
I agree... if the compiler could literally point out spelling mistakes to people, then that would put an end to people like me looking stupid by posting stupid questions on forums!
Karl Taylor