Daniel Fernandez Daniel Fernandez - 1 year ago 97
iOS Question

Variable NSString anos working with NSLocalizedString Xcode

I am developing an app in Xcode using Objective-c and I have a problem with an NSStrign variable and NSLocalizedString (to translate to other idioms).

My problem is that if I use this way, it works great:
(All this code is in my ViewDidLoad method)

NSString *decDate = @"11/2016";
_updateLabel.text = [NSString stringWithFormat:@"Updated: %@", decDate];

And the result is:

Updated: 11/2016

But if I try to use NSLocalizedString to translate this String, it doesn't´t works:

NSString *decDate = @"11/2016";
_updateLabel.text = [NSString stringWithFormat:NSLocalizedString (@"Updated: %@", decDate)];

In this case, Xcode said me "Unused variable 'decDate'"

And the result is:

Updated: NSString

Can someone help me? Thank you very much!

Answer Source

NSLocalizedString takes two arguments, the key and a comment. You're using decDate as the comment.

Your stringWithFormat should look like this:

 [NSString stringWithFormat:NSLocalizedString(@"Updated: %@", nil), decDate]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download