How to use SwiftUI with macOS 10.15

I am new to swift and Xcode. I would like to create a new project and I would like to use SwiftUI. The issue is that I need to offer support to my user base where some users are still using macOS 10.15.

I am using Xcode 14. After naming my project and selecting the option to create a SwiftUI project I will go to my project target then I change it to macOS 10.15 however I get errors like @main, Scene, WindowGroup is only supported in macOS 11 and newer.

Is there a way that I can setup a project to use SwiftUI and still target macOS 10.15?
Also is there any resources where I can download Xcode 12 default SwiftUI project, for some reason my computer will not allow me to downgrade Xcode?

Could someone provide a example please

Welcome to the community! This is going to get a little complicated, because you’re new to this, but it all has to do with how new SwiftUI is (only released in 2019), and how much it is still constantly changing since it’s release.

You should use this tool, Xcodes, with an “s” to download Xcode, rather than using the Mac App Store. This tool allows you to have multiple versions of Xcode downloaded at once (something the Mac App Store doesn’t), and given that, you can easily switch between versions and use whichever one you want (as long as your macOS version is compatible). This tool technically just uses Apple’s website to download Xcode, rather than the Mac App Store, and given that it names them differently, which allows you to select different versions.

SwiftUI works with macOS 10.15, but as you’ve found, there are tons and tons of changes since the first release. (see here for details about compatibility, mentioned at the top).

I would not recommend downloading Xcode 12 and using that default project, because at some point Apple makes it so that you must use an updated version of Xcode to submit apps. (This is typically for iOS, but there are requirements for macOS too, but it depends how you deploy the app). This is an iOS forum more so, so we can help more on that front, than macOS.

You can see here that WindowGroup is only available to macOS 11.0+, as you’ve found.

What I’d recommend doing, is starting the project NOT using SwiftUI (because this will give you the right starting files and then instead use SwiftUI views. Which means you’ll have to do UIKit / SwiftUI interoperability. (BUT actually with it being macOS, you’ll have to interact with AppKit, not UIKit, because UIKit is an iOS framework and AppKit is macOS)

See some details here about SwiftUI / UIKit: SwiftUI and UIKit interoperability - Part 1 | Swift by Sundell
AppKit: AppKit | Apple Developer Documentation