3

If you create a new SwiftUI app in Xcode 12 and use the SwiftUI App Lifecycle this struct is generated... When you build for Mac it's generating this error. Apple has noted @main is an issue in their Xcode 12 release notes (https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes)

People have discussed workaround for AppDelegate class.. but it does not work for SwiiftUI App Lifecycle (which you select when you create a new SwiftUI App project for iPhone)(iOS Xcode 12.0 Swift 5 'AppDelegate' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void

Does anyone have a workaround for this yet, other than switching to AppDelegate and SceneDelegate.

//@main
@UIApplicationMain // @UIApplicationMain may only be used on 'class' declarations
struct MyApp: App { // Cannot find type 'App' in scope
    var body: some Scene { // Cannot find type 'Scene' in scope
        WindowGroup {
            ContentView()
        }
    }
}

EDIT:

This is the error I get when I use the @main attribute:

'MyApp' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void.

I can add the static main function part but it still doesn't resolve the can't find app in scope or scene in scope issues.

 @main
 struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            MainView()
        }
    }

    static func main() -> Void {
    
    }
}

EDIT EDIT:

Note this does not resolve my issue... It still complains about the @main attribute SwiftUI app life cycle iOS14 where to put AppDelegate code?

visc
  • 4,794
  • 6
  • 32
  • 58
  • @Asperi right I understand that... But you can't compile SwiftUI App Lifecycle apps since Xcode12 GM release.. During the betas I had no problem with the `@main` attribute – visc Sep 22 '20 at 18:00

1 Answers1

2

You need to use Xcode 12.2 and fresh beta of macOS 11

Sound Blaster
  • 4,778
  • 1
  • 24
  • 32