title: How to detect and change ios app language using Swift?
body: <p>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.</p>
  
  <p>I used the following to detect the language:</p>
  
  <pre><code>let lang: String = NSLocale.preferredLanguages()[0] as String
  </code></pre>
  
  <p>However this will return "en" for me even my iOS simulator is set to Arabic language.</p>
  
  <p>Based on Objective-C questions, I tried to do the following to change the language to Arabic:</p>
  
  <pre><code>NSUserDefaults.setValue("ar", forKey: "AppleLanguage")
  </code></pre>
  
  <p>But this issues an error:</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[&lt;NSUserDefaults 0x103daa350&gt; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key AppleLanguage.'
  </code></pre>