In my macOS GUI app I need to show only one window. If the user closes it, the app should also close.
So I can do it as such:
@main
struct MyApp: App {
var body: some Scene
{
Window("my title",
id: "idMyWindow")
{
ContentView()
.onAppear
{
//Code that runs when app is shown
}
}
}
}
But I also need to have my app run on macOS v.12. When I change that the compiler tells me that Window
is not available. So I need to revert back to WindowGroup
for an older OS.
So I tried this instead:
@main
struct MyApp: App {
var body: some Scene
{
if #available(macOS 13.0, *)
{
Window("my title",
id: "idMyWindow")
}
else
{
WindowGroup
}
{
ContentView()
.onAppear
{
//Code that runs when app is shown
}
}
}
}
But evidently that is not how you use #available
in that case.
Any idea how shall I change it to make it work?