I’m seeing the same issue on my iPad Pro 11”
FB9121354: Swift Playgrounds on iPad does not update UI for @State variables
The code works on Mac, not on iPad Playgrounds.
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var isSelected: Bool = true
@State var useRedText = false
var body: some View {
VStack {
Text("SwiftUI on iPad")
.font(.headline)
.padding(20)
.background(Color.red)
.cornerRadius(10)
Text("Paul Rocks!")
.font(.largeTitle)
.padding(20)
.background(isSelected ? Color.orange : Color.blue) //color())
.cornerRadius(30)
.onTapGesture {
print("Paul Rocks")
isSelected.toggle()
}
Button("Hello World") {
// flip the Boolean between true and false
self.useRedText.toggle()
}
.foregroundColor(useRedText ? .red : .blue)
}
}
func color() -> Color {
isSelected ? Color.orange : Color.blue
}
}
PlaygroundPage.current.setLiveView(ContentView())
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: