如何在Xcode 12的新SwiftUI App生命周期中更改window.rootViewController?

时间:2020-10-17 00:54:00

标签: ios swift swiftui

我是SwiftUI的新手。我有一个新项目Test,它运行SwiftUI界面和SwiftUI App生命周期。此生命周期是iOS 14和Xcode 12的新功能。

我想在我的项目中使用Github软件包BetterSheet。我已经添加了包依赖。但是,如Basic Usage section of the readme中所述,我必须在UIHostingController中的工作表支持下初始化SceneDelegate.swift,就像这样:

window.rootViewController = UIHostingController.withBetterSheetSupport(rootView: ContentView())

由于新生命周期的性质,我的应用没有SceneDelegate.swift。我改为TestApp.swift

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

我想在我的项目中使用BetterSheet包,但是第一步似乎很麻烦。我该如何解决?

1 个答案:

答案 0 :(得分:1)

我怀疑您可以执行类似的操作,based on their UIHostingController+BetterSheet.swift代码。

if 0 in itertools.chain(*BOARD_EASY):
  do the thing

但是我会质疑这个库的价值。具有标准库的iOS 14中的工作表演示效果很好,并且库本身14个月都没有更新。