问题描述
我正在尝试通过 Swift Playgrounds 在 iPad 上使用 SwiftUI。下面的视图最初呈现良好,但不幸的是,当 @State
更改时,视图不会更新,就像在我的 Mac 上一样。在小侧边栏中,我可以看到闭包确实得到了执行...
我使用的是最新的非测试版。
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())
谢谢。
解决方法
见https://developer.apple.com/forums/thread/677361。 Enable Results
应该关闭。