【问题标题】:Using Xcode 12 build errors for target macOS 10.15对目标 macOS 10.15 使用 Xcode 12 构建错误
【发布时间】: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()。)

标签: xcode macos swiftui


【解决方案1】:

感谢@Raja Kishan,答案就是在创建新项目时在 Lifecycle 的选项中选择 App Delegate 选项。

【讨论】:

  • 您能将此标记为解决方案吗?可能会为其他人节省一些时间。谢谢!
  • 哇 - 两天搜索互联网并完全重新安装,这就是我所需要的 - 谢谢......!希望我能给这个 +10。
  • 是的,谢谢。花了几天时间搜索这个。
猜你喜欢
  • 1970-01-01
  • 2020-12-03
  • 2021-01-18
  • 2021-01-03
  • 1970-01-01
  • 2021-10-27
  • 2020-02-06
  • 1970-01-01
  • 2018-03-30
相关资源
最近更新 更多