英文:
SwiftUI Development for macOS 10.15 with Xcode 14: Errors and Setup
问题
我正在使用macOS Veneer和Xcode 14开发一个目标版本设置为macOS 10.15的macOS应用程序。由于我对SwiftUI编程还不熟悉,在将目标版本更改为macOS 10.15时,遇到了一些错误:
- "'main()'仅在macOS 11.0或更新版本中可用"
- "'Scene'仅在macOS 11.0或更新版本中可用"
- "'WindowGroup'仅在macOS 11.0或更新版本中可用"
我正在寻求如何设置项目以启用SwiftUI编程,同时将目标版本定为macOS 10.15的指导。我注意到默认项目模板中没有AppDelegate.swift文件。
我知道从Xcode 12开始,SwiftUI变得可用。是否有任何资源或链接,我可以下载旧版本Xcode的默认项目模板?我的计算机现在不允许我打开旧版本的Xcode。
英文:
I'm using macOS Veneer and Xcode 14 to develop a macOS application with a target development set to macOS 10.15. As I'm new to coding with SwiftUI, I encountered a few errors when I changed the target to macOS 10.15:
- "'main()' is only available in macOS 11.0 or newer"
- "'Scene' is only available in macOS 11.0 or newer"
- "'WindowGroup' is only available in macOS 11.0 or newer"
I'm seeking guidance on how to set up the project to enable SwiftUI coding while targeting macOS 10.15. I've noticed that there is no AppDelegate.swift file in the default project template.
I'm aware that starting from Xcode 12, SwiftUI became available. Are there any resources or links where I can download default project templates for older Xcode versions? My computer will now allow me to open older Xcode versions.
答案1
得分: -1
SwiftUI首次在2019年的Xcode 11中发布,并支持macOS 10.15(Catalina)。但是,SwiftUI应用程序生命周期,包括App
和Scene
协议、WindowGroup
类型和@main
注释,首次出现在2020年的Xcode 12中,并需要macOS 11(Big Sur)。
如果您想支持macOS 10.15,就不能使用SwiftUI应用程序生命周期。您需要使用AppKit生命周期。为此,在创建项目时,请选择macOS应用程序项目模板。然后,在界面选项中,选择Storyboard或XIB。这些选项截止到Xcode 15.0 beta 1仍然可用,因此您不需要下载其他资源。
请注意,自macOS 10.15以来,SwiftUI已经有了很大的改进。您可能会发现开发一个使用SwiftUI并支持macOS 10.15的应用程序只会带来更多的麻烦。至少,您需要在macOS 10.15上彻底测试您的用户界面,而不仅仅是在后续版本上,因为后续版本中进行了许多错误修复和微妙的行为更改。我的日常工作涉及维护一款内部Mac应用程序,直到我的所有用户都升级到至少macOS 12之前,我并没有觉得开始使用SwiftUI是值得的。
您可以在虚拟机中运行macOS 10.15进行测试,但(我认为)只有拥有英特尔Mac的情况下才能这样做。我认为Apple Silicon Mac无法运行英特尔虚拟机,而macOS 10.15不支持Apple Silicon。
英文:
SwiftUI first shipped with Xcode 11 in 2019 and supported macOS 10.15 (Catalina). But the SwiftUI app lifecycle, which includes the App
and Scene
protocols, the WindowGroup
type, and the @main
annotation, first appeared in Xcode 12 in 2020 and required macOS 11 (Big Sur).
If you want to support macOS 10.15, you cannot use the SwiftUI app lifecycle. You need to use the AppKit lifecycle. To do that, when creating your project, choose the macOS App project template. Then, for the Interface option, choose either Storyboard or XIB. These options are still available as of Xcode 15.0 beta 1, so you should not need to download any other resources.
Please be aware that SwiftUI has improved a lot since macOS 10.15. You may find that developing an app that uses SwiftUI and supports macOS 10.15 is simply more trouble than it’s worth. At a minimum you’ll need to test your user interface thoroughly on macOS 10.15 and not just on later versions, because there have been a lot of bug fixes and subtle behavioral changes in later releases. My day job involves maintaining an in-house Mac app, and I didn’t find it worthwhile to start using SwiftUI until all my users were on at least macOS 12.
You can run macOS 10.15 in a virtual machine for testing, but (I think) only if you have an Intel Mac. I do not think Apple Silicon Macs can run an Intel VM, and macOS 10.15 didn’t support Apple Silicon.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论