How to get current language code with Swift?

user3739367 picture user3739367 · Jul 6, 2014 · Viewed 119k times · Source

I want get the language code of the device (en, es...) in my app written with Swift. How can get this?

I'm trying this:

var preferredLanguages : NSLocale!
let pre = preferredLanguages.displayNameForKey(NSLocaleIdentifier, value: preferredLanguages)

But this returns nil.

Answer

Vadim Motorine picture Vadim Motorine · Oct 12, 2016

In Swift 3

let langStr = Locale.current.languageCode