1

I would like to change the current locale programmatically. I tried searching in stackoverflow and found this way.

[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

But my question is how to set it to the currentLocale, but [NSLocale currentLocale] returns the currentLocale. But how do I set it?

Need some guidance on this.

lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • 1
    no changing the language... changing the region format... – lakshmen Jun 15 '13 at 10:57
  • 1
    @GabrielePetronella I am not looking for changing the language on the fly. Looking for changing the region format... – lakshmen Jun 15 '13 at 12:28
  • 3
    You should not (and cannot) change the current locale, but rather to create a new `NSLocale` object like you have above, and then use this locale object for whatever purposes you need (e.g. calling the `setLocale` of a `NSDateFormatter`). – Rob Jun 15 '13 at 13:17

1 Answers1

0

I think you can change language programmtically so that Locale will change accordingly.

UserDefaults.standard.set(["en_us"], forKey: "AppleLanguages")

although i didn't get time to try this solution(In swift)