How to handle having more than 10 WindowGroups and ImmersiveSpaces?

Hi, I'm building an app that has more than 10 Window Groups and Immersive Spaces.

I ran into an issue where if I have more than 10, It won't compile with an error saying Extra arguments in call.

Eg:

WindowGroup(id: "Window 1"){
            Debug()
        }.defaultSize(width: 1000, height: 800)

...


ImmersiveSpace(id: "Space 11"){
            Debug()
        }.immersionStyle(selection: .constant(.mixed), in: .mixed)

I fixed it by grouping a bunch of window groups and was able to run my app, but soon realised that grouping does not work for Immersive Spaces because as soon as I opened an Immersive space from one of the groupings, It crashes citing an error from SceneManifest. It thinks the app boots up to an Immersive Space.

It looks like this:

Group {
WindowGroup(id: "Window 1"){
            Debug()
        }.defaultSize(width: 1000, height: 800)
...

WindowGroup(id: "Window 11"){
            Debug()
        }.defaultSize(width: 1000, height: 800)
}

Group {
ImmersiveSpace(id: "Space 1"){
            IMView()
        }.immersionStyle(selection: .constant(.mixed), in: .mixed)
}

....

ImmersiveSpace(id: "Space 11"){
            IMView()
        }.immersionStyle(selection: .constant(.mixed), in: .mixed)
}

SwiftUI/UIKitAppDelegate.swift:770: Fatal error: Your app was given a scene with session role UISceneSessionRole(_rawValue: UISceneSessionRoleImmersiveSpaceApplication) but no scenes declared in your App body match this role.

I can fix this by removing the groupings and having them be if I reduce the amount of views and windows.

Is there a way to overcome this limitation?

Use Group, with no more than 10 direct children in each Group.

https://developer.apple.com/forums/thread/740677

Hi @SravanKaruturi!

While using Group is one way of addressing this, I'm curious if you could reduce the number of WindowGroup and ImmersiveSpace that you need to have defined in your app. Is it possible that you instead of defining several different scenes, you would swap the content displayed by the scene? It really depends on your use case, though.

--

Regarding the crash you've mentioned: This is a great finding, and I think our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software.

I'd greatly appreciate it if you could open a bug report, including the code snippet you've posted here, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

How to handle having more than 10 WindowGroups and ImmersiveSpaces?
 
 
Q