Class

NSLocale

NSLocale objects encapsulate information about linguistic, cultural, and technological conventions and standards. Examples of information encapsulated by a locale include the symbol used for the decimal separator in numbers and the way dates are formatted.

Overview

You typically use NSLocale objects to format interpret information about and according to the user’s customs and preferences. They are frequently used in conjunction with formatters (see Data Formatting Guide). Although you can use many locales, you usually use the one associated with the current user (see Getting and Initializing Locales).

NSLocale is “toll-free bridged” with its Core Foundation counterpart, CFLocale. See Toll-Free Bridging for more information on toll-free bridging.

Nested Types

NSLocaleLanguageDirection

These constants describe the text direction for a language. Used by the methods lineDirection(forLanguage:) and characterDirection(forLanguage:).

NSLocaleKey

Symbols

Getting and Initializing Locales

init(localeIdentifier: String)

Initializes the receiver using a given locale identifier.

Getting Information About a Locale

var localeIdentifier: String

Returns the identifier for the locale.

var countryCode: String?

Returns the country code for the locale.

var languageCode: String

Returns the language code for the locale.

var scriptCode: String?

Returns the script code for the locale.

var variantCode: String?

Returns the variant code for the locale.

var exemplarCharacterSet: CharacterSet

Returns the exemplar character set for the locale.

var collationIdentifier: String?

Returns the collation identifier for the locale.

var collatorIdentifier: String

Returns the collator identifier for the locale.

var usesMetricSystem: Bool

Returns whether the locale uses the metric system.

var decimalSeparator: String

Returns the decimal separator for the locale.

var groupingSeparator: String

Returns the grouping separator for the locale.

var currencyCode: String?

Returns the currency code for the locale.

var currencySymbol: String

Returns the currency symbol for the locale.

var quotationBeginDelimiter: String

Returns the begin quotation symbol for the locale.

var quotationEndDelimiter: String

Returns the end quotation symbol for the locale.

var alternateQuotationBeginDelimiter: String

Returns the alternate begin quotation symbol for the locale.

var alternateQuotationEndDelimiter: String

Returns the alternate end quotation symbol for the locale.

func object(forKey: NSLocale.Key)

Returns the object corresponding to the specified key.

Getting Display Information About a Locale

func localizedString(forLocaleIdentifier: String)

Returns the localized string for the specified locale identifier.

func localizedString(forCountryCode: String)

Returns the localized string for the specified country code.

func localizedString(forLanguageCode: String)

Returns the localized string for the specified language code.

func localizedString(forScriptCode: String)

Returns the localized string for the specified script code.

func localizedString(forVariantCode: String)

Returns the localized string for the specified variant code.

func localizedString(forCollationIdentifier: String)

Returns the localized string for the specified collation identifier.

func localizedString(forCollatorIdentifier: String)

Returns the localized string for the specified collator identifier.

func localizedString(forCurrencyCode: String)

Returns the localized string for the specified currency code.

func displayName(forKey: NSLocale.Key, value: Any)

Returns the display name for the given value.

Converting Between Identifiers

class func canonicalLocaleIdentifier(from: String)

Returns the canonical identifier for a given locale identification string.

class func components(fromLocaleIdentifier: String)

Returns a dictionary that is the result of parsing a locale ID.

class func localeIdentifier(fromComponents: [String : String])

Returns a locale identifier from the components specified in a given dictionary.

class func canonicalLanguageIdentifier(from: String)

Returns a canonical language identifier by mapping an arbitrary locale identification string to the canonical identifier.

class func localeIdentifier(fromWindowsLocaleCode: UInt32)

Returns a locale identifier from a Windows locale code.

class func windowsLocaleCode(fromLocaleIdentifier: String)

Returns a Window locale code from the locale identifier.

Getting Line and Character Direction For a Language

class func characterDirection(forLanguage: String)

Returns the direction of the sequence of characters in a line for the specified ISO language code.

class func lineDirection(forLanguage: String)

Returns the direction of the sequence of lines for the specified ISO language code.

Constants

LanguageDirection

These constants describe the text direction for a language. Used by the methods lineDirection(forLanguage:) and characterDirection(forLanguage:).

NSLocale Component Keys

The following constants specify keys used to retrieve components of a locale with object(forKey:).

Locale Calendar Identifiers

These constants identify types of calendars. For more information, see Locales and Calendars in the NSCalendar class reference.

Notifications

class let currentLocaleDidChangeNotification: NSNotification.Name

Notification that indicates that the user’s locale changed.

Relationships

Inherits From