init(_:)
Creates a text view that displays a stored string without localization.
Declaration
init<S>(_ content: S) where S : StringProtocolParameters
- content:
The string value to display without localization.
Discussion
Use this initializer to create a text view that displays — without localization — the text in a string variable.
Text(someString) // Displays the contents of `someString` without localization.SwiftUI doesn’t call the init(_:) method when you initialize a text view with a string literal as the input. Instead, a string literal triggers the init(_:tableName:bundle:comment:) method — which treats the input as a LocalizedStringKey instance — and attempts to perform localization.
By default, SwiftUI assumes that you don’t want to localize stored strings, but if you do, you can first create a localized string key from the value, and initialize the text view with that. Using a key as input triggers the init(_:tableName:bundle:comment:) method instead.