user198725878
user198725878

Reputation: 6386

Initialiser element is not a compile time constant

In my constant file, I have included the below line

NSString * ALERT_OK = NSLocalizedString(@"Ok",@"Ok");

After this, when I tried to compile I am receiving the below error

Initialiser element is not a compile time constant

How can I debug this?

Upvotes: 3

Views: 481

Answers (1)

lnafziger
lnafziger

Reputation: 25740

The problem is that NSLocalizedString is a function which returns different values, depending on the language. It is not a constant which can be figured out until the system is running.

Instead, use:

 #define ALERT_OK NSLocalizedString(@"Ok",@"Ok");

And it will now simply replace ALERT_OK with the function and you will be fine. (Note that you should be using some kind of prefix to all global values like this so that you don't accidentally create something with the same name being used somewhere else.)

Upvotes: 5

Related Questions