Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

Swift Playgrounds on iPad Not Working with SwiftUI code as Expected

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())
question from:https://stackoverflow.com/questions/65831546/swift-playgrounds-on-ipad-not-working-with-swiftui-code-as-expected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...