Brand new SwiftUI apps not building for Catalyst on Xcode 12 GM

My Catalyst-capable apps stopped building with the newly released Xcode 12. I tested it out also on a brand new SwiftUI project with the same result. I have my App structure looking like the fragment below. This is the code that was generated by Xcode; no modifications.

Code Block swift
import SwiftUI
@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}


I get the following compiler errors:
  • 'TestApp' 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

This code compiles fine when I build for an iPhone or iPad device.

Is anyone else seeing this? Any ideas on how to fix it?
Answered by szymczyk in 634785022
The Xcode 12.0 GM seed does not include the macOS 11 SDK, which the new SwiftUI app cycle requires for Mac apps.

You will have to install the Xcode 12.2 beta and use that until macOS 11 ships.

Somewhere amongst the xcode 12 release notes, there is:

Known Issues
A newly-created iOS project using the Swift language may no longer build after enabling Mac Catalyst. (67885114)

Workaround: Replace the @main annotation on the App Delegate with @UIApplicationMain.

I saw that. Unfortunately, that opens up more issues and it still doesn't build. Switching out @main for @UIApplicationMain leads to "@UIApplicationMain may only be used on 'class' declarations. It also is still reporting that the compiler can't find App or Scene in scope.

To use @UIApplicationMain, I'd need to change TestApp from a struct to a class, but then I'll get the error that 'UIApplicationMain' class must conform to the 'UIApplicationDelegate' protocol.
Disclaimer: I'm a total noob to Xcode & SwiftUI.

How do you actually "replace the @main annotation on the app delegate with @UIApplicationMain"?

My project is named "SwiftUiTest20200921" and I tried opening SwiftUiTest20200921.swift at the compile error. When I change "@main" to "@UIApplicationMain" and immediately get an error saying that "@UIApplicationMain may only be used on 'class' declarations".

Here's the code:
Code Block
import SwiftUI
@UIApplicationMain
struct SwiftUiTest20200921App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}


Any ideas?

Thanks!
Accepted Answer
The Xcode 12.0 GM seed does not include the macOS 11 SDK, which the new SwiftUI app cycle requires for Mac apps.

You will have to install the Xcode 12.2 beta and use that until macOS 11 ships.

Brand new SwiftUI apps not building for Catalyst on Xcode 12 GM
 
 
Q