This problem which I know should be very easy has stumped me for hours.
I try to get a random element from a simple Array into a Text in SwiftUI but i get errors I don't understand, the recent error I got was:
Instance method 'appendInterpolation' requires that '[Result]' conform to '_FormatSpecifiable'
What would be the simplest way to implement this? I understand this has been answered many times but I am too bad at coding to understand when I try to google it.
struct Result: Identifiable {
var id = UUID()
var score: Int
}
struct ContentView: View {
@State private var showDetails = false
@State var results = [Result(score: 8),
Result(score: 5),
Result(score: 10)]
var body: some View {
VStack {
Button(action: {
self.results.randomElement()
}) {
Text("Button title, \(results)")
}
}
}
}