0

I'm wondering what's wrong with the following, or how to fix the brackets correctly:

if (([newCharacter isEqual: @"ö"]||[newCharacter isEqual: @"Ö"]) && (self.currentLanguage isEqual @"Finnish/Swedish")){
//do something
}

the error says I should place parantheses somewhere... but I cannot figure out how. Can anyone help?

suMi
  • 1,536
  • 1
  • 17
  • 30

2 Answers2

2

If you change this:

(self.currentLanguage isEqual @"Finnish/Swedish")

to this:

[self.currentLanguage isEqual:@"Finnish/Swedish"]

you should be ok. You need square brackets and a colon there to have a proper expression for sending the isEqual message, and no extra () parentheses are needed after the &&.

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75
  • I don't think it's true that using `isEqual:` means you will only compare memory addresses. Both `isEqual:` and `isEqualToString:` should have the same results for any comparison of two string objects. @viperking's answer links to a good discussion on this. In short, I'd say that for most code it really doesn't make a meaningful difference other than style preferences. – Mike Mertsock Jan 12 '14 at 16:25
1

You are missing : after isEqual in this: self.currentLanguage isEqual @"Finnish/Swedish"

So your code should looks like:

if (([newCharacter isEqual: @"ö"]||[newCharacter isEqual: @"Ö"]) && (self.currentLanguage isEqual: @"Finnish/Swedish")){
   //do something
}

I would also recommend you a change of isEqual: to isEqualToString: as it is more obvious what are you comparing and also has some performance issues according to this question

Community
  • 1
  • 1
Julian
  • 9,299
  • 5
  • 48
  • 65