Structure

Locale

Information about linguistic, cultural, and technological conventions for use in formatting data for presentation.

Overview

Locale encapsulates 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.

Locales are typically used to provide, format, and interpret information about and according to the user’s customs and preferences. They are frequently used in conjunction with formatters. Although you can use many locales, you usually use the one associated with the current user.

Topics

Creating a Locale

init(identifier: String)

Creates a locale with the specified identifier.

Getting the User's Locale

static var autoupdatingCurrent: Locale

A locale which tracks the user’s current preferences.

static var current: Locale

A locale representing the user's region settings at the time the property is read.

Getting Known Identifiers and Codes

static var availableIdentifiers: [String]

A list of available identifiers.

static var isoRegionCodes: [String]

A list of available region codes.

static var isoLanguageCodes: [String]

A list of available language codes.

static var isoCurrencyCodes: [String]

A list of available currency codes.

static var commonISOCurrencyCodes: [String]

A list of common currency codes.

Converting Between Identifiers

static func canonicalIdentifier(from: String)

Returns a canonical identifier from the given string.

static func components(fromIdentifier: String)

Returns a dictionary that splits an identifier into its component pieces.

static func identifier(fromComponents: [String : String])

Constructs an identifier from a dictionary of components.

static func canonicalLanguageIdentifier(from: String)

Returns a canonical language identifier from the given string.

static func identifier(fromWindowsLocaleCode: Int)

Returns the locale identifier from a given Windows locale code, or nil if it could not be converted.

static func windowsLocaleCode(fromIdentifier: String)

Returns the Windows locale code from a given identifier, or nil if it could not be converted.

Getting Information About a Locale

var identifier: String

The identifier of the locale.

var calendar: Calendar

The calendar for the locale, or the Gregorian calendar as a fallback.

var regionCode: String?

The region code of the locale, or nil if it has none.

var languageCode: String?

The language code of the locale, or nil if has none.

var scriptCode: String?

The script code of the locale, or nil if has none.

var variantCode: String?

The variant code for the locale, or nil if it has none.

var exemplarCharacterSet: CharacterSet?

The exemplar character set for the locale, or nil if has none.

var collationIdentifier: String?

The collation identifier for the locale, or nil if it has none.

var collatorIdentifier: String?

The collator identifier of the locale.

var usesMetricSystem: Bool

A Boolean that is true if the locale uses the metric system.

var decimalSeparator: String?

The decimal separator of the locale.

var groupingSeparator: String?

The grouping separator of the locale.

var currencyCode: String?

The currency code of the locale.

var currencySymbol: String?

The currency symbol of the locale.

var quotationBeginDelimiter: String?

The quotation begin delimiter of the locale.

var quotationEndDelimiter: String?

The quotation end delimiter of the locale.

var alternateQuotationBeginDelimiter: String?

The alternate quotation begin delimiter of the locale.

var alternateQuotationEndDelimiter: String?

The alternate quotation end delimiter of the locale.

Getting Display Information About a Locale

func localizedString(for: Calendar.Identifier)

Returns a localized string for a specified calendar.

func localizedString(forCollationIdentifier: String)

Returns a localized string for a specified ICU collation identifier.

func localizedString(forCollatorIdentifier: String)

Returns a localized string for a specified ICU collator identifier.

func localizedString(forCurrencyCode: String)

Returns a localized string for a specified ISO 4217 currency code.

func localizedString(forIdentifier: String)

Returns a localized string for a specified locale identifier.

func localizedString(forLanguageCode: String)

Returns a localized string for a specified language code.

func localizedString(forRegionCode: String)

Returns a localized string for a specified region code.

func localizedString(forScriptCode: String)

Returns a localized string for a specified script code.

func localizedString(forVariantCode: String)

Returns a localized string for a specified variant code.

Getting the User's Preferred Languages

static var preferredLanguages: [String]

A list of the user’s preferred languages.

Getting Line and Character Direction for a Language

static func characterDirection(forLanguage: String)

Returns the character direction for a specified language code.

static func lineDirection(forLanguage: String)

Returns the line direction for a specified language code.

typealias Locale.LanguageDirection

An alias for the standard set of language directions.

enum NSLocale.LanguageDirection

The directions that a language may take across a page of text.

Comparing Locales

static func !=(Locale, Locale)

Returns a Boolean value indicating whether two values are not equal.

static func ==(Locale, Locale)

Returns a Boolean indicating whether two locales are identical.

Describing a Locale

var description: String

A textual description of the locale.

var debugDescription: String

A textual description of the locale suitable for debugging.

var customMirror: Mirror

A mirror that reflects the locale.

var hashValue: Int

The computed hash value for the locale.

Using Reference Types

class NSLocale

An object representing information about linguistic, cultural, and technological conventions that bridges to Locale; use NSLocale when you need reference semantics or other Foundation-specific behavior.

typealias Locale.ReferenceType

An alias for this value type's equivalent reference type.

Instance Methods