【发布时间】:2021-03-29 10:43:52
【问题描述】:
从 Xcode 12.3 开始,当您使用 macOS 目标创建新的 SwiftUI 项目时,Xcode 会将目标默认为 11.0 (Big Sur)。 在不更改默认创建的默认“hello world”应用程序中的一行代码的情况下,我将目标更改为 macOS 10.15(我仍在使用) 默认项目 swift 文件将不再构建。:-
@main
struct catalinaApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}```
3 Errors: @main, 'Scene' and WindowGroup is only available in macOS 11.0 or newer
How can I alter the project/above file to correctly build the default app on Catalina? (10.15) ?
thanks in advance!
【问题讨论】:
-
检查这个:developer.apple.com/documentation/swiftui/windowgroup。 WindowGroup 至少需要 Mac OS 11,因此将您的项目目标设置为至少 11
-
谢谢 - 上面的文档确认 WindowGroup 需要 macOS 11。问题是,macOS 10.15 的等价物是什么?在 macOS 11 出现之前,macOS 应用程序使用了哪些代码?
-
使用旧的生命周期 - AppDelegate。创建新项目时可用的选项。
-
完美 - 谢谢!我不知道生命周期选项。使用 AppDelegate 选项还将 macOS 10.15 设置为默认目标,并且可以完美编译。 (有趣的是,App Delegate 版本的 Hello World 使用 .frame(),而新的 SwiftUI 生命周期使用 .padding()。)