appendInterpolation(_:)
Appends an attributed substring to a string interpolation.
Declaration
@export(implementation) mutating func appendInterpolation(_ attributedSubstring: AttributedSubstring)Parameters
- attributedSubstring:
The attributed substring to append.
Discussion
Don’t call this method directly; it’s used by the compiler when interpreting string interpolations.
The following example shows how to use a string interpolation to format an AttributedSubstring and append it to static text. The resulting interpolation implicitly creates a LocalizedStringKey, which a Text view uses to provide its content.
struct ContentView: View {
var identificationNumberSuffix: AttributedSubstring {
// …
}
var body: some View {
Text("Identification: •••• •••• \(identificationNumberSuffix)!")
}
}For this example, assume that the app runs on a device set to a Russian locale, and has the following entry in a Russian-localized Localizable.strings file:
"Identification: •••• •••• %@" = "Идентификация: •••• •••• %@";The attributed string identificationNumberSuffix replaces the format specifier %@, maintaining its color attributes, when the Text view renders its contents: