在 Xcode 11 playground 中使用 SwiftUI

Eva*_*n C 2 swift-playground swiftui xcode11

我知道如何在常规应用程序项目中使用 Xcode 11 中的 SwiftUI,但我想知道是否有办法在 Playgrounds 中使用它,即使我无法使用实时编辑器?

And*_*era 5

当然,这很简单:

import PlaygroundSupport

PlaygroundPage.current.liveView = UIHostingController(rootView: PlaygroundRootView())

public struct PlaygroundRootView: View {
    public init() {}

    public var body: some View {
        Text("Hello World!")
    }
}
Run Code Online (Sandbox Code Playgroud)

在此处查看更多信息:https : //github.com/attoPascal/SwiftUI-Tutorial-Playground