首页 > 解决方案 > 在 Xcode 11 Playground 中使用 SwiftUI

问题描述

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

标签: swift-playgroundswiftuixcode11

解决方案


当然,这很容易:

import PlaygroundSupport

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

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

    public var body: some View {
        Text("Hello World!")
    }
}

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


推荐阅读