I've been following Apple's SwiftUI tutorials. Along the way, I've often used the Text
object with the following initializer:
/// Creates an instance that displays `content` verbatim.
public init<S>(_ content: S) where S : StringProtocol
Now, in the fifth tutorial of the series, I've encountered the following usage of Text
:
Text(verbatim: "")
The description in the interface is the same as for the other initializer:
/// Creates an instance that displays `content` verbatim.
public init(verbatim content: String)
What's the two initializers for and how are they different / when would I use which?
Text(verbatim: )
returns text as it is - hence the verbatim argument name.
Text(:_)
checks if the argument is a localized key.
If it is, it returns the corresponding localized string.
It it isn't, it will print the text verbatim.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With