Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocalizedString - Format not a string literal and no format arguments (xcode)

I get the "format not a string..." message when doing the following:

NSString* string1 = [[NSString alloc] initWithFormat:NSLocalizedString(@"Update Now", @"Update Now Item")];
NSString* string2 = [[NSString alloc] initWithFormat:NSLocalizedString(@"Register", @"Register Now")];

It works fine i.e. the app doesn't crash on the device or simulator, and the localized text displays just fine also.

I'm trying to understand why is it then that I'm getting this particular error message. As far as I'm aware this is how you're meant to use localized strings in Objective C.

like image 225
Siberian Avatar asked Apr 08 '26 18:04

Siberian


1 Answers

Simplest way to use localized string is:

NSString* myString = NSLocalizedString(@"Update Now",@"Update Now");

Now keep in mind myString is autoreleased - which you would generally need for a string.

In the examples you give your strings are retained (because you use initWithFormat). Guessing "update now" and such are going to be shown in the user UI, possibly trough a UILabel you don't need a retained string - when you do assign the string to a UILabel it will retain it automatically (as the text is stored in a retained property)

like image 137
Marin Todorov Avatar answered Apr 11 '26 08:04

Marin Todorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!