locale(_:)
Modifies the format style to use the specified locale.
Declaration
func locale(_ locale: Locale) -> IntegerFormatStyle<Value>Parameters
- locale:
The locale to apply to the format style.
Return Value
An integer format style modified to use the provided locale.
Discussion
Use this modifier to change the locale used by an existing format style. To instead determine the locale this format style uses, use the locale property.
The following example creates a default IntegerFormatStyle for the en_US locale, and applies the notation(_:) modifier to use compact name notation. Next, the sample creates a second style based on this first style, but using the German (DE) locale. It then applies each style to an array of integers.
let compactStyle = IntegerFormatStyle<Int>(locale: Locale(identifier: "en_US"))
.notation(.compactName)
let germanStyle = compactStyle.locale(Locale(identifier:"DE"))
let nums = [100, 1000, 10000, 100000, 1000000]
let enUSCompactNums = nums.map { compactStyle.format($0) } // ["100", "1K", "10K", "100K", "1M"]
let deCompactNums = nums.map { germanStyle.format($0) } // ["100", "1000", "10.000", "100.000", "1 Mio."]