首页 > 解决方案 > 使用 SwiftUI、XCode 12 和 Catalina 的新项目失败

问题描述

我正在尝试创建一个新的 XCode 项目,全新的,我可以在模拟器上运行它,但在画布上它说:Cannot preview in this file - active scheme does not build this file 如果最重要的是我开始添加 macOS 支持,它说:

'appName' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void.它还说:

Cannot find type 'App' in scope

Cannot find type 'Scene' in scope

关于我正在阅读的 mac 支持,有一个解决方法,即使我尝试过并且错误仍然存​​在。

至于活动方案,我读过这个,但没有帮助。我的意思是......一个新项目中只有一个方案,它是自动选择的

我会假设一个简单的 hello world 项目会起作用,这是怎么回事?

标签: swiftxcodeswiftuimacos-catalinaxcode12

解决方案


macOS 上的 SwiftUI 2.0仅从Big-Sur macOS 11.0开始可用

@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
public protocol App {
                    ^^^^^^^^^^^^

推荐阅读