struct StringInterpolation
The string interpolation to use as the localization key.
Availability 有効性
Technology
init(stringInterpolation: LocalizedStringKey
.StringInterpolation
)
stringInterpolation
The string interpolation to use as the localization key.
To create a localized string key from a string interpolation, use the \()
string interpolation syntax. Swift matches the parameter types in the expression to one of the append
methods in Localized
. The interpolated types can include numeric values, Foundation types, and SwiftUI Text
and Image
instances.
The following example uses a string interpolation with two arguments: an unlabeled Date
and a Text
labeled style
. The compiler maps these to the method append
as it builds the string that it creates the Localized
with.
let key = LocalizedStringKey("Date is \(company.foundedDate, style: .offset)")
let text = Text(key) // Text contains "Date is +45 years"
You can write this example more concisely, implicitly creating a Localized
as the parameter to the Text
initializer:
let text = Text("Date is \(company.foundedDate, style: .offset)")
struct StringInterpolation