6

As of Xcode 12.3, when you create a new SwiftUI project with a target of macOS, Xcode defaults the target to 11.0 (Big Sur). Without changing a line of code in the default "hello world" app created by default, I then change the target to macOS 10.15 (which is what I am still using) The default project swift file will no longer build.:-


@main
struct catalinaApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}```

3 Errors: @main, 'Scene' and WindowGroup is only available in macOS 11.0 or newer

How can I alter the project/above file to correctly build the default app on Catalina? (10.15) ?

thanks in advance!
4
  • 2
    Check this : developer.apple.com/documentation/swiftui/windowgroup. WindowGroup is required minimum Mac OS 11 so set you’re project target minimum 11 Commented Dec 18, 2020 at 19:30
  • 1
    Thanks - the documentation above confirms that WindowGroup requires macOS 11. The question is, what is the equivalent for macOS 10.15? What code was used for macOS apps before macOS 11 came out? Commented Dec 18, 2020 at 19:40
  • 3
    Use old lifecycle - AppDelegate. Option available when you create new project. Commented Dec 18, 2020 at 19:42
  • Perfect - thank you! I wasn't aware of the lifecycle option. Using the AppDelegate option also sets macOS 10.15 as the default target, and it compiles perfectly. (Interesting to note that the App Delegate version of Hello World uses a .frame(), whereas the new SwiftUI lifecycle uses .padding(). ) Commented Dec 18, 2020 at 19:56

1 Answer 1

13

Thanks to @Raja Kishan, the answer is simply to choose the App Delegate option in the choices for Lifecycle when creating a new project.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you mark this as solution? Might save others some time. Thanks!
Wow - two days searching the internet and a full reinstall and this was ALL I needed - thanks...! Wish I could give this +10.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.