Wednesday
May062009
NSString - Comparing two strings in Objective-C
Comparing strings in Obj-C is not done the same way as comparing two integers, bools, or even characters. For example, the following code will fail to get the desired results:
if (someString == @"someText") { // do stuff }
This will never run, because you are comparing pointers and not the content of the two strings. Instead, use this:
if ([someString isEqualToString:@"someText"]) { // do stuff }
Rob Zimmerman
Reader Comments