RayX1993 RayX1993 - 4 months ago 58
iOS Question

Conditional code based on a device's language in Swift

I'm trying to create if statements based on the device's language.

For instance:
if device's language is English ()
else if device's language is Spanish ()
else if device's language is Arabic ()

but cannot figure out how to do it.


You can use NSLocale's preferredLanguages method:

let language = NSLocale.preferredLanguages[0]

if language.hasPrefix("en") {
else if language.hasPrefix("ar") {