Alberto Schiariti
Alberto Schiariti

Reputation: 1579

Objective-C IF statement with OR condition

What's wrong in this IF statement?

if ([currentElement isEqualToString:@"aaa" || currentElement isEqualToString:@"bbb"])

XCode says:

No visible @interface for 'NSString' declares the selector 'isEqualToString:isEqualToString:'

I'm into an NSXML Parser procedure if it can help, but I think it's not that the problem.

Upvotes: 11

Views: 27751

Answers (1)

Vladimir
Vladimir

Reputation: 170819

You must compare result of two method calls:

if ([currentElement isEqualToString:@"aaa"] || [currentElement isEqualToString:@"bbb"])

The code you have actually compiles as

if ([currentElement isEqualToString:(@"aaa"||currentElement) isEqualToString:@"bbb"])

that is compiler tries to call non-existing isEqualToString:isEqualToString: method of NSString

Upvotes: 33

Related Questions