The attached code works as expected on the Playgrounds simulator for the Mac but the States don't register a view update when the same code runs on an iPad. Does anyone know of a known issue/fix/workaround?
import SwiftUI
import PlaygroundSupport
struct MathGame: View
{
@State var showAnswer = false
@State var answer = ""
@State var x = Int.random(in: 0...100)
@State var y = Int.random(in: 0...100)
var body: some View
{
VStack
{
Text(x.description)
Text(y.description)
if showAnswer
{
let z = x + y
Text(z.description)
} else
{
Text(" ")
}
Button("Next Question")
{
showAnswer = false
x = Int.random(in: 0...100)
y = Int.random(in: 0...100)
}
Spacer()
Toggle(isOn: $showAnswer)
{
Text("Show Answer")
}
}.padding().font(.system(size: 64))
}
}
PlaygroundPage.current.setLiveView(MathGame())
