I want to detect which language the user have for the device. Then I want to change the language to a different language the app will load appropriate images, strings, storyboards.
I used the following to detect the language:
let lang: String = NSLocale.preferredLanguages() as String
NSUserDefaults.setValue("ar", forKey: "AppleLanguage")
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSUserDefaults 0x103daa350> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key AppleLanguage.'
With the code you made, compiler think you're trying to use KVO, setting the value "ar" to the property "AppleLanguage" of the NSUserDefaults class. Which doesn't exist.
setObject:forKey: instead of
NSUserDefaults.setObject(["ar"], forKey: "AppleLanguage") // First param is an array.
And I never coded in Swift, but don't you need to get the standard defaults
NSUserDefaults.standardUserDefaults() before updating anything in it?