Instance Method


Returns the display name for the given locale component value.


func displayName(forKey key: NSLocale.Key, value: Any) -> String?



The locale property key of value. For possible values, see NSLocale.Key.


A value for key.

Return Value

The display name for value.


Not all locale property keys have values with display name values.

You can use the identifier key to get the name of a locale in the language of another locale, as illustrated in the following examples.

let frLocale = NSLocale(localeIdentifier: "fr_FR")
print(frLocale.displayNameForKey(NSLocaleIdentifier, value: "fr_FR")!)
// "français (France)”
print(frLocale.displayNameForKey(NSLocaleIdentifier, value: "en_US")!)
// "anglais (États-Unis)”

The following example uses the en_GB locale.

let gbLocale = NSLocale(localeIdentifier: "en_GB")
print(gbLocale.displayNameForKey(NSLocaleIdentifier, value: "fr_FR")!)
// "French (France)”
print(gbLocale.displayNameForKey(NSLocaleIdentifier, value: "en_US")!)
// "English (United States)”

See Also

Accessing Locale Information by Key

func object(forKey: NSLocale.Key) -> Any?

Returns the value of the component corresponding to the specified key.

struct NSLocale.Key

The keys used to access components of a locale.