How can I change the locale for my app programmatically via Swift?

daaniaal picture daaniaal · Dec 28, 2014 · Viewed 8.3k times · Source

I have a language selection control in my application, and I want to be able to set the locale accordingly during runtime. How can I achieve this?

Answer

daaniaal picture daaniaal · Dec 28, 2014

I found the answer

NSUserDefaults.standardUserDefaults().setObject(["fr"], forKey: "AppleLanguages")
NSUserDefaults.standardUserDefaults().synchronize()

Swift 3:

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