-3

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

fabian
  • 43
  • 1
  • 5

3 Answers3

6

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
  • 7,830
  • 2
  • 41
  • 42
1

You should use isEqualToString Is it necessary to assign a string to a variable before comparing it to another?

Community
  • 1
  • 1
Yaroslav
  • 2,718
  • 17
  • 16
0

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
  • 10,355
  • 2
  • 46
  • 60