【问题标题】:How can i run Scene and App on swiftUI using ipad Playground for swift如何使用 ipad Playground 在 swiftUI 上运行 Scene 和 App 以实现 swift
【发布时间】:2021-11-03 17:17:14
【问题描述】:

我使用 Apple ipad pro M1 来编写 Swift 和 SwiftUI,但现在我停在这里,因为我现在不知道应该如何处理这个错误

代码:

import SwiftUI
import PlaygroundSupport

struct Welcoming:App {
var body: some Scene {
    WindowGroup {
        TabView {
            Text("one")
            Text("tow")
            }
        }
    }
}

还有错误:

没有完全匹配调用'setLiveView'实例方法

This image for the code and error

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    setLiveView 将 SwiftUI View 作为参数。您正在尝试发送Welcoming,它被定义为App。相反,将您的视图封装成一个View,您可以发送到PlaygroundPage

    struct ContentView : View {
        var body: some View {
            TabView {
                Text("one")
                    .tabItem {
                        Text("One")
                    }
                Text("two")
                    .tabItem {
                        Text("Two")
                    }
            }
        }
    }
    
    PlaygroundPage.current.setLiveView(ContentView())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      相关资源
      最近更新 更多