我开始了一个SwiftUI
项目,iOS 15
作为部署目标,我被要求降低版本,所以我将其更改为 iOS 13,在解决了一些代码兼容性问题后,我在应用程序的入口点出现错误,MyProjectApp.swift
说main()
and Scene
and WindowGroup
are仅适用于 iOS 14+
如何使入口点与低于 iOS 14.x 的版本兼容?
这是我的入口点的代码
@main //'main()' is only available in iOS 14.0 or newer
struct MyProjectApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene { //'Scene' is only available in iOS 14.0 or newer
WindowGroup { //'WindowGroup' is only available in iOS 14.0 or newer
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
}
}