iPad Pro running iOS 14.4, Playgrounds App version 3.4
Super simple @State example doesn’t update the UI. Clicking the button increments the tapCount variable, but the UI doesn’t update to show the new value. Isn’t it supposed to?
Am I using an old code example or otherwise doing something wrong? This exact same code works fine on a Playground in Xcode.
Swift
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State private var tapCount = 0
var body: some View {
Button("Tap count: \(tapCount)") {
tapCount += 1
}
}
}
PlaygroundPage.current.setLiveView(ContentView())