Reputation: 4959
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?
Upvotes: 3
Views: 1521