Season's Greetings, NSHipsters!
As the year winds down, and we take a moment to reflect on our experiences over the past months, one thing is clear: 2014 has been an incredible year professionally for Apple developers. So much has happened in such a short timespan, and yet it's hard to remember our relationship to Objective-C before Swift, or what APIs could have captivated our imagination as much as iOS 8 or WatchKit.
It's an NSHipster tradition to ask you, dear readers, to send in your favorite tips and tricks from the past year for publication over the New Year's holiday. This year, with the deluge of new developments—both from Cupertino and the community at large—there should be no shortage of interesting tidbits to share.
Submit your favorite piece of Swift or Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!
If you're wondering about what to post, look to past year's write-ups for inspiration (2014, 2013).
I can't wait to see what you all send in!
Sometimes, you need to know which language your app is running in. Often, people will use +[NSLocale preferredLanguages]. Unfortunately this tells nothing about the language the app is actually displaying. It will just give you the ordered list as found in Settings → General → Language & Region → Preferred Language Order on iOS or System Preferences → Language & Region → Preferred Languages on OS X.
Imagine that the preferred language order is {English, French} but your app is German only. Calling
[[NSLocale preferredLanguages] firstObject]
will give you English when you want German.The proper way to get the actual language used by the app is to use [[NSBundle mainBundle] preferredLocalizations].
From the documentation:
From a comment in NSBundle.h:
You may also need to use +[NSLocale canonicalLanguageIdentifierFromString:] in order to ensure a canonical language identifier.