MeasurementSystem
- iOS
- 16+
- macOS
- 13+
- tvOS
- 16+
- watchOS
- 9+
struct MeasurementSystem
struct MeasurementSystem
import FoundationEssentials
struct Locale
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.
init(components: Locale.Components)
Creates a Locale
with the specified locale components
init(from decoder: any Decoder) throws
init(identifier: String)
Return a locale with the specified identifier.
init(identifier: String, preferences: LocalePreferences?)
init(languageCode: Locale.LanguageCode? = nil, script: Locale.Script? = nil, languageRegion: Locale.Region? = nil)
init(languageComponents: Locale.Language.Components)
Creates a Locale
with the specified language components
static var autoupdatingCurrent: Locale { get }
Returns a locale which tracks the user’s current preferences.
static var current: Locale { get }
Returns the user’s current locale.
static var preferredLanguages: [String] { get }
Returns a list of the user’s preferred languages.
static func canonicalIdentifier(from string: String) -> String
Returns a canonical identifier from the given string.
static func canonicalLanguageIdentifier(from string: String) -> String
Returns a canonical language identifier from the given string.
static func identifier(fromComponents components: [String : String]) -> String
Constructs an identifier from a dictionary of components.
static func identifierDoesNotRequireSpecialCaseHandling(_ identifier: String) -> Bool
var alternateQuotationBeginDelimiter: String? { get }
Returns the alternate quotation begin delimiter of the locale.
var alternateQuotationEndDelimiter: String? { get }
Returns the alternate quotation end delimiter of the locale.
var availableNumberingSystems: [Locale.NumberingSystem] { get }
Returns all the valid numbering systems for the locale. For example, "ar-AE (Arabic (United Arab Emirates)"
has both "latn" (Latin digits)
and "arab" (Arabic-Indic digits)
numbering system.
var calendar: Calendar { get }
Returns the calendar for the locale, or the Gregorian calendar as a fallback.
var collation: Locale.Collation { get }
Returns the default collation used by the locale. Default is .standard
.
var collationIdentifier: String? { get }
Returns the collation identifier for the locale, or nil if it has none.
var collatorIdentifier: String? { get }
Returns the collator identifier of the locale.
var currency: Locale.Currency? { get }
Returns the currency of the locale. Returns nil if the data isn’t available.
var currencyCode: String? { get }
Returns the currency code of the locale.
var currencySymbol: String? { get }
Returns the currency symbol of the locale.
var customMirror: Mirror { get }
var debugDescription: String { get }
var decimalSeparator: String? { get }
Returns the decimal separator of the locale.
var description: String { get }
var firstDayOfWeek: Locale.Weekday { get }
Returns the first day of the week of the locale. Returns .sunday
as the default value if the data isn’t available to the requested locale.
var forceHourCycle: Locale.HourCycle? { get }
var forceMeasurementSystem: Locale.MeasurementSystem? { get }
var forceTemperatureUnit: LocalePreferences.TemperatureUnit? { get }
var groupingSeparator: String? { get }
Returns the grouping separator of the locale.
var hourCycle: Locale.HourCycle { get }
Returns the hour cycle such as whether it uses 12-hour clock or 24-hour clock. Default is .zeroToTwentyThree
if the data isn’t available. Calling this on .current
or .autoupdatingCurrent
returns user’s preference values as set in the system settings if available, overriding the default value of the user’s locale.
var identifier: String { get }
Returns the identifier of the locale.
var identifierCapturingPreferences: String { get }
var language: Locale.Language { get }
var languageCode: String? { get }
Returns the language code of the locale, or nil if has none.
var measurementSystem: Locale.MeasurementSystem { get }
var numberingSystem: Locale.NumberingSystem { get }
Returns the numbering system of the locale. If the locale has an explicitly specified numbering system in the identifier (e.g. bn_BD@numbers=latn
) or in the associated Locale.Components
, that numbering system is returned. Otherwise, returns the default numbering system of the locale. Returns "latn"
as the default value if the data isn’t available.
var prefs: LocalePreferences? { get }
var quotationBeginDelimiter: String? { get }
Returns the quotation begin delimiter of the locale.
var quotationEndDelimiter: String? { get }
Returns the quotation end delimiter of the locale.
var region: Locale.Region? { get }
Returns the region of the locale. For example, “US” for “en_US”, “GB” for “en_GB”, “PT” for “pt_PT”.
var regionCode: String? { get }
Returns the region code of the locale, or nil if it has none.
var scriptCode: String? { get }
Returns the script code of the locale, or nil if has none.
var subdivision: Locale.Subdivision? { get }
Returns the regional subdivision for the locale, or nil if there is none.
var temperatureUnit: LocalePreferences.TemperatureUnit { get }
var timeZone: TimeZone? { get }
var usesMetricSystem: Bool { get }
Returns true if the locale uses the metric system.
var variant: Locale.Variant? { get }
Returns the variant for the locale, or nil if it has none. For example, for the locale “en_POSIX”, returns “POSIX”.
var variantCode: String? { get }
Returns the variant code for the locale, or nil if it has none.
static func == (lhs: Locale, rhs: Locale) -> Bool
func encode(to encoder: any Encoder) throws
func forceFirstWeekday(_ calendar: Calendar.Identifier) -> Locale.Weekday?
func forceMinDaysInFirstWeek(_ calendar: Calendar.Identifier) -> Int?
func hash(into hasher: inout Hasher)
func identifier(_ type: Locale.IdentifierType) -> String
func localizedString(for calendarIdentifier: Calendar.Identifier) -> String?
Returns a localized string for a specified Calendar.Identifier
.
func localizedString(forCollationIdentifier collationIdentifier: String) -> String?
Returns a localized string for a specified ICU collation identifier.
func localizedString(forCollatorIdentifier collatorIdentifier: String) -> String?
Returns a localized string for a specified ICU collator identifier.
func localizedString(forCurrencyCode currencyCode: String) -> String?
Returns a localized string for a specified ISO 4217 currency code.
func localizedString(forIdentifier identifier: String) -> String?
Returns a localized string for a specified identifier.
func localizedString(forLanguageCode languageCode: String) -> String?
Returns a localized string for a specified language code.
func localizedString(forRegionCode regionCode: String) -> String?
Returns a localized string for a specified region code.
func localizedString(forScriptCode scriptCode: String) -> String?
Returns a localized string for a specified script code.
func localizedString(forVariantCode variantCode: String) -> String?
Returns a localized string for a specified variant code.
struct Collation
struct Components
Represents locale-related attributes. You can use Locale.Components
to create a Locale
with specific overrides.
struct Currency
enum HourCycle
enum IdentifierType
struct Language
struct LanguageCode
enum LanguageDirection
struct NumberingSystem
struct Region
struct Script
struct Subdivision
struct Variant
enum Weekday
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol ExpressibleByExtendedGraphemeClusterLiteral : ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single extended grapheme cluster.
protocol ExpressibleByStringLiteral : ExpressibleByExtendedGraphemeClusterLiteral
A type that can be initialized with a string literal.
protocol ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single Unicode scalar value.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
init(_ identifier: String)
The complete list of valid measurement systems can be found here, under the key with the name “ms”
init(from decoder: any Decoder) throws
init(stringLiteral value: String)
static let cldrKeywordKey: ICUCLDRKey
static let legacyKeywordKey: ICULegacyKey
static var measurementSystems: [Locale.MeasurementSystem] { get }
Returns a list of measurement systems
static let metric: Locale.MeasurementSystem
Metric system
static let uk: Locale.MeasurementSystem
UK System of measurement: feet, pints, etc.; pints are 20oz
static let us: Locale.MeasurementSystem
US System of measurement: feet, pints, etc.; pints are 16oz
var debugDescription: String { get }
var identifier: String { get set }
static func == (lhs: Locale.MeasurementSystem, rhs: Locale.MeasurementSystem) -> Bool
func encode(to encoder: any Encoder) throws
func hash(into hasher: inout Hasher)
init(extendedGraphemeClusterLiteral value: Self.StringLiteralType)
init(unicodeScalarLiteral value: Self.ExtendedGraphemeClusterLiteralType)
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.