@State 不适用于 iPad Swift Playgrounds

问题描述

我正在尝试通过 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/677361Enable Results 应该关闭。