views:

70

answers:

4

Hi,

my if clause always runs into the else statement? Whats the fault?

        NSLog([[category objectForKey:@"id"] stringValue]); // Traces 15
        if ([[category objectForKey:@"id"] stringValue] == "15") {
            result.isExternal = YES;
        } else {
            result.isExternal = NO;
        }

thanks for helping

+1  A: 

You should use isEqualToString http://stackoverflow.com/questions/1302985/how-do-i-compare-strings-in-objective-c

Yaroslav
+5  A: 

You should change

[[category objectForKey:@"id"] stringValue]

to

[[[category objectForKey:@"id"] stringValue] isEqualToString:@"15"]

And as for comparing that stringValue how you are, you need to do == @"15" as "15" isn't a string unless an @ is infront.

Garrett
Thanks, but I still run into the else statement.
fabian
Then try comparing the `intValue` like so: `[[[category objectForKey:@"id"] intValue] isEqualToNumber:[NSNumber numberWithInt:15]]`
Garrett
@Garrett `intValue` returns an `int`, which means you can do `[... intValue] == 15`
Dave DeLong
Gah, was just editing my original answer, forgot you should do what you said. Thanks!
Garrett
A: 

Your "if" statement is comparing two C strings with "==". You should use strcmp for that. If your function returns an objective C string, you should use @"15", and the correct comparison function.

tonio
A: 

It Works! Thank you!

fabian
Edit your question instead, but where do you create the result object?
Brandon Bodnár
ok, its working! Thanks
fabian
If you got it working make sure to accept the answer that helped you along. I am thinking that is Garrett's.
Brandon Bodnár
I don't think he's coming back :(
Garrett