Alexander
Alexander

Reputation: 301

Changing app language from code doesn't work in iOS

I try to switch app language from code in my iOS app. I do this

    var lang = "en"        
    print("lang 1 = \(lang)")
    print("lang 2 = \(UserDefaults.standard.array(forKey: "AppleLanguages")![0])")

    UserDefaults.standard.setValue([lang], forKey: "AppleLanguages")
    UserDefaults.standard.synchronize()

    print("lang 3 = \(UserDefaults.standard.array(forKey: "AppleLanguages")![0])")

And the code above prints this.

lang 1 = en
lang 2 = es
lang 3 = es

Why 'lang' is not saved to UserDefaults? What I have missed?

Upvotes: 2

Views: 373

Answers (1)

EvGeniy Ilyin
EvGeniy Ilyin

Reputation: 1929

I had a identical problem, most likely it's a case in the configuration of the run scheme, if in application language is non set system language the parameter will be forced.enter image description here in this case you will not be able to overwrite AppleLanguages

Upvotes: 1

Related Questions