String comparison in Objective-C


I've currently got a webserver set up which I communicate over SOAP with my iPhone app. I am returning a string containing a GUID and when I attempt to compare this with another string I get some strange results.

Why would this not fire? Surely the two strings are a match?

NSString *myString = @"hello world";

if(myString == @"hello world")
    return;

Answers:


Use the -isEqualToString: method to compare the value of two strings. Using the C == operator will simply compare the addresses of the objects.

if ([category isEqualToString:@"Some String"])
{
    // Do stuff...
}