简体   繁体   中英

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM