Skip to content

Initializer

init(components:)

iOS 16.0+ iPadOS 16.0+ Mac Catalyst 16.0+ macOS 13.0+ tvOS 16.0+ watchOS 9.0+
Creates a locale from the given components.
init(components: Locale.Components)

Parameters

components

A Locale.Components instance that provides the components to create a customized locale.

Discussion

Use this initializer to create a locale with a unique combination of components, beyond the defaults provided by a language and country code.

For example, you can create a Locale.Components instance that uses UK language conventions, but US regional conventions for traits like currency and measurement. You then use the components to create a new Locale instance, like this:

var components = Locale.Components(languageCode: "en", languageRegion: "GB")
components.region = Locale.Region("US")
let en_GB_US = Locale(components: components)