views:

255

answers:

2

Hey,

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:

alt text

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

Thanks

+7  A: 

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...
}
jlehr
AH! Thanking you muchly. Feel like a bit of a fool on this one!
ing0
My guess is that in ObjectiveC++ you could create an operator overload to give you syntactically-sugary ability to use == but no sane objective C programmer would do this, because == is only used for identity checks in objective C objects.
Warren P
+2  A: 

You can use Case Sensitive or Case Insensitive comparison, depending what you need. Case Sensitive is like this:

if ([category isEqualToString:@"Some String"])
{
   doSomething = YES;
}

Case Insensitive is like this:

if (!([category compare:@"Some String" options:NSCaseInsensitiveSearch]))
{
   doSomething = YES;
}
mxg