Looking to pass in a generic type Value that can be represented in a string in a Text("\(value)"
Now literally the only two possible data types would be String and Double ( or some other number type) so maybe I'm going down the wrong rabbit hole here so I'm open for suggestions in the best path to take..
Here is an example of what I'm trying to do..
struct AnswerView<Value: ExpressibleByStringLiteral>: View {
let value: Value
var body: some View {
Text("Your answer is \(value)") //<--Error: No exact matches in call to instance method 'appendInterpolation'
}
}
Use String(describing:):
Text("Your answer is \(String(describing: value))")
or (very similarly):
struct AnswerView<Value: CustomStringConvertible>: View {
let value: Value
var body: some View {
Text("Your answer is \(value.description)")
}
}
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