<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSLocale",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLocale"
  },
  "title" : "NSLocale"
}
-->

# NSLocale

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

```
class NSLocale
```

## Overview

In Swift, this object bridges to [`Locale`](/documentation/Foundation/Locale); use [`NSLocale`](/documentation/Foundation/NSLocale) when you need reference semantics or other Foundation-specific behavior.

You typically use a locale to format and interpret information about and according to the user’s customs and preferences.

You can initialize any number of locale instances with [`init(localeIdentifier:)`](/documentation/Foundation/NSLocale/init(localeIdentifier:)) using one of the locale identifiers found in the [`availableLocaleIdentifiers`](/documentation/Foundation/NSLocale/availableLocaleIdentifiers) array. However, you usually use a locale configured to match the preferences of the current user.

Use the [`current`](/documentation/Foundation/NSLocale/current) property to get the locale matching the current user’s preferences. If you need to be alerted when the user does make changes to region settings, register for the [`currentLocaleDidChangeNotification`](/documentation/Foundation/NSLocale/currentLocaleDidChangeNotification) notification. Alternatively, you can use the [`autoupdatingCurrent`](/documentation/Foundation/NSLocale/autoupdatingCurrent) property to get a locale that automatically updates with the user’s configuration settings:

```objc
NSLocale* locale = [NSLocale autoupdatingCurrentLocale];
```

You can inspect a locale by reading its properties, as listed in Getting Information About a Locale. For properties containing a code or identifier, you can then obtain a string suitable for presentation to the user with the methods listed in Getting Display Information About a Locale. For example, you can report the user’s language as a string localized in that language using the autoupdating locale obtained in the previous example:

```objc
NSString* code = locale.languageCode;
NSString* language = [locale localizedStringForLanguageCode:code];

NSLog(@"%@",language);
// Prints "English" for locale en_US, "français" for fr_FR
```

You frequently use a locale in conjunction with a formatter. For example, the [`DateFormatter`](/documentation/Foundation/DateFormatter) class has a [`locale`](/documentation/Foundation/DateFormatter/locale) property that ensures dates are converted to strings that match the user’s expectations about date formatting. By default, this property indicates the user’s current locale, which is usually the behavior you want, but you can instead set it to another locale instance to obtain a different output. See [Data Formatting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i) for more information about working with formatters.

[`NSLocale`](/documentation/Foundation/NSLocale) is *toll-free bridged* with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFLocale>. See [Toll-Free Bridging](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2) for more information on toll-free bridging.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/Locale`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSLocale`` class. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Initializing a Locale

[`+ (instancetype) localeWithLocaleIdentifier:(NSString *) ident;`](/documentation/Foundation/NSLocale/localeWithLocaleIdentifier:)

Returns a locale initialized using the given locale identifier.

[`init(localeIdentifier: String)`](/documentation/Foundation/NSLocale/init(localeIdentifier:))

Initializes a locale using a given locale identifier.

[`init?(coder: NSCoder)`](/documentation/Foundation/NSLocale/init(coder:))

Returns a locale initialized from data in the given unarchiver.

### Getting the User’s Locale

[`class var autoupdatingCurrent: Locale`](/documentation/Foundation/NSLocale/autoupdatingCurrent)

A locale which tracks the user’s current preferences.

[`class var current: Locale`](/documentation/Foundation/NSLocale/current)

A locale that represents the user’s region settings at the time the property is read.

[`class let currentLocaleDidChangeNotification: NSNotification.Name`](/documentation/Foundation/NSLocale/currentLocaleDidChangeNotification)

A notification that indicates that the user’s locale changed.

[`class var system: Locale`](/documentation/Foundation/NSLocale/system)

A locale representing the generic root values with little localization.

### Getting Known Identifiers and Codes

[`class var availableLocaleIdentifiers: [String]`](/documentation/Foundation/NSLocale/availableLocaleIdentifiers)

The list of locale identifiers available on the system.

[`class var isoCountryCodes: [String]`](/documentation/Foundation/NSLocale/isoCountryCodes)

The list of known country or region codes.

[`class var isoLanguageCodes: [String]`](/documentation/Foundation/NSLocale/isoLanguageCodes)

The list of known language codes.

[`class var isoCurrencyCodes: [String]`](/documentation/Foundation/NSLocale/isoCurrencyCodes)

The list of known currency codes.

[`class var commonISOCurrencyCodes: [String]`](/documentation/Foundation/NSLocale/commonISOCurrencyCodes)

A list of commonly encountered currency codes.

### Converting Between Identifiers

[`class func canonicalLocaleIdentifier(from: String) -> String`](/documentation/Foundation/NSLocale/canonicalLocaleIdentifier(from:))

Returns the canonical identifier for a given locale identification string.

[`class func components(fromLocaleIdentifier: String) -> [String : String]`](/documentation/Foundation/NSLocale/components(fromLocaleIdentifier:))

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

[`class func localeIdentifier(fromComponents: [String : String]) -> String`](/documentation/Foundation/NSLocale/localeIdentifier(fromComponents:))

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

[`class func canonicalLanguageIdentifier(from: String) -> String`](/documentation/Foundation/NSLocale/canonicalLanguageIdentifier(from:))

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

[`class func localeIdentifier(fromWindowsLocaleCode: UInt32) -> String?`](/documentation/Foundation/NSLocale/localeIdentifier(fromWindowsLocaleCode:))

Returns a locale identifier from a Windows locale code.

[`class func windowsLocaleCode(fromLocaleIdentifier: String) -> UInt32`](/documentation/Foundation/NSLocale/windowsLocaleCode(fromLocaleIdentifier:))

Returns a Window locale code from the locale identifier.

### Getting Information About a Locale

[`var localeIdentifier: String`](/documentation/Foundation/NSLocale/localeIdentifier)

The identifier for the locale.

[`var countryCode: String?`](/documentation/Foundation/NSLocale/countryCode)

The country or region code for the locale.

[`var languageCode: String`](/documentation/Foundation/NSLocale/languageCode)

The language code for the locale.

[`var scriptCode: String?`](/documentation/Foundation/NSLocale/scriptCode)

The script code for the locale.

[`var variantCode: String?`](/documentation/Foundation/NSLocale/variantCode)

The variant code for the locale.

[`var exemplarCharacterSet: CharacterSet`](/documentation/Foundation/NSLocale/exemplarCharacterSet)

The exemplar character set for the locale.

[`var collationIdentifier: String?`](/documentation/Foundation/NSLocale/collationIdentifier)

The collation identifier for the locale.

[`var collatorIdentifier: String`](/documentation/Foundation/NSLocale/collatorIdentifier)

The collator identifier for the locale.

[`var usesMetricSystem: Bool`](/documentation/Foundation/NSLocale/usesMetricSystem)

A Boolean value that indicates whether the locale uses the metric system.

[`var decimalSeparator: String`](/documentation/Foundation/NSLocale/decimalSeparator)

The decimal separator for the locale.

[`var groupingSeparator: String`](/documentation/Foundation/NSLocale/groupingSeparator)

The grouping separator for the locale.

[`var currencyCode: String?`](/documentation/Foundation/NSLocale/currencyCode)

The currency code for the locale.

[`var currencySymbol: String`](/documentation/Foundation/NSLocale/currencySymbol)

The currency symbol for the locale.

[`var calendarIdentifier: String`](/documentation/Foundation/NSLocale/calendarIdentifier)

The calendar identifier for the locale.

[`var quotationBeginDelimiter: String`](/documentation/Foundation/NSLocale/quotationBeginDelimiter)

The begin quotation symbol for the locale.

[`var quotationEndDelimiter: String`](/documentation/Foundation/NSLocale/quotationEndDelimiter)

The end quotation symbol for the locale.

[`var alternateQuotationBeginDelimiter: String`](/documentation/Foundation/NSLocale/alternateQuotationBeginDelimiter)

The alternate begin quotation symbol for the locale.

[`var alternateQuotationEndDelimiter: String`](/documentation/Foundation/NSLocale/alternateQuotationEndDelimiter)

The alternate end quotation symbol for the locale.

### Getting Display Information About a Locale

[`func localizedString(forLocaleIdentifier: String) -> String`](/documentation/Foundation/NSLocale/localizedString(forLocaleIdentifier:))

Returns the localized string for the specified locale identifier.

[`func localizedString(forCountryCode: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forCountryCode:))

Returns the localized string for a country or region code.

[`func localizedString(forLanguageCode: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forLanguageCode:))

Returns the localized string for the specified language code.

[`func localizedString(forScriptCode: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forScriptCode:))

Returns the localized string for the specified script code.

[`func localizedString(forVariantCode: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forVariantCode:))

Returns the localized string for the specified variant code.

[`func localizedString(forCollationIdentifier: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forCollationIdentifier:))

Returns the localized string for the specified collation identifier.

[`func localizedString(forCollatorIdentifier: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forCollatorIdentifier:))

Returns the localized string for the specified collator identifier.

[`func localizedString(forCurrencyCode: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forCurrencyCode:))

Returns the localized string for the specified currency code.

[`func localizedString(forCalendarIdentifier: String) -> String?`](/documentation/Foundation/NSLocale/localizedString(forCalendarIdentifier:))

Returns the localized string for the specified calendar identifier.

[Locale Calendar Identifiers](/documentation/Foundation/locale-calendar-identifiers)

The types of calendars.

### Accessing Locale Information by Key

[`func object(forKey: NSLocale.Key) -> Any?`](/documentation/Foundation/NSLocale/object(forKey:))

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

[`func displayName(forKey: NSLocale.Key, value: Any) -> String?`](/documentation/Foundation/NSLocale/displayName(forKey:value:))

Returns the display name for the given locale component value.

[`struct Key`](/documentation/Foundation/NSLocale/Key)

The keys used to access components of a locale.

### Getting the User’s Preferred Languages

[`class var preferredLanguages: [String]`](/documentation/Foundation/NSLocale/preferredLanguages)

An ordered list of the user’s preferred languages.

### Getting Line and Character Direction for a Language

[`class func characterDirection(forLanguage: String) -> NSLocale.LanguageDirection`](/documentation/Foundation/NSLocale/characterDirection(forLanguage:))

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

[`class func lineDirection(forLanguage: String) -> NSLocale.LanguageDirection`](/documentation/Foundation/NSLocale/lineDirection(forLanguage:))

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

[`enum LanguageDirection`](/documentation/Foundation/NSLocale/LanguageDirection)

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

### Instance Properties

[`var languageIdentifier: String`](/documentation/Foundation/NSLocale/languageIdentifier)

Returns the identifier for the language part of the locale. For example, returns “en-US” for “en_US@rg=gbzzzz”  locale.

[`var regionCode: String?`](/documentation/Foundation/NSLocale/regionCode)

Returns the region code of the locale.
If the `rg` subtag is present, the value of the subtag will be used. For example,  returns “GB” for “en_US@rg=gbzzzz” locale.
If the `localeIdentifier` doesn’t contain a region, returns `nil`.

## See Also

  [Internationalization and Localization Guide](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/Introduction/Introduction.html#//apple_ref/doc/uid/10000171i)

  [Data Formatting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i)

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Escapable`](/documentation/Swift/Escapable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Sendable`](/documentation/Swift/Sendable)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Copyable`](/documentation/Swift/Copyable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)