SwiftUI PlaygroundBook 我无法访问其他视图

SwiftUI PlaygroundBook I can't access the other View

我无法从 WelcomeView 访问 GameView。如何在 Playground Book 中获取页面导航?

错误

Cannot find "Game View" in scope

欢迎查看

import SwiftUI
import PlaygroundSupport

struct WelcomeView: View {
    var body: some View {
        GameView()
    }
}
PlaygroundPage.current.setLiveView(WelcomeView())

游戏视角

import SwiftUI
import PlaygroundSupport

struct GameView: View {
    var body: some View {
        Text("GameView")
    }
}
PlaygroundPage.current.setLiveView(GameView())

欢迎查看图片

游戏查看图片

您应该将 public 访问级别添加到您的 classes/properties/methods/properties。这样您就可以从 main 游乐场访问它们。


public struct GameView: View {

  public init() { }

  public var body: some View {
    Text("GameView")
  }
}