mercredi 20 mai 2015

iOS inline if else compile error: "Expected : "; "Expected expression"

I am learning iOS programming (I come from Android) and I am looking for get Strings more easy. With this propose I define the next macro and use it in some code fragment:

#define STRING_BASE @"InfoPlist"
#define getString(string) NSLocalizedStringFromTable(string, STRING_BASE, @"");

...

BOOL isSomething = YES; //or NO
_label.text = isSomething? @"YES" : @"NO";
_label.text = isSomething? @"YES" : getString(@"login_title");
_label.text = isSomething? getString(@"login_title") : @"NO";

I don't know what happened , when I have this 2 lines all its ok, and it works.

_label.text = isSomething? @"YES" : @"NO";
_label.text = isSomething? @"YES" : getString(@"login_title");

But when I use the last one I have a compiler error that says "Expected : " and "Expected expression".

_label.text = isSomething? getString(@"login_title") : @"NO";

If I choose "Fix-it" the code is replacement for this (and continue with compiler error, of course):

self.loginTitleLabel.text = isSomething? : ) : @"NO";

There are something that I did wrong?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire