Limit of the number of ImmersiveSpace ids?

In a visionOS's App file I run into the compile time error Extra argument in call for a 10th ImmersiveSpace declaration. Commenting this declaration and leaving the 9 others, removes this error.

Why does this behaviour occur? I haven't come across any limitations regarding the permitted number of ImmersiveSpace declarations in the App file. The only limit I recall is that ONLY 1 immersive space may be loaded by the app an any given time during runtime.

The issue is easily reproducible in latest Xcode 15.1 beta 2 :

  • create a new visionOS app with:
    • initial scene of Window,
    • Immersive Space Renderer RealityKit, and
    • Immersive Space Mized
  • in App file, under body, copy paste the ImmersiveSpace block 10 times, renaming the id's ImmersiveSpace1 through to ImmersiveSpace10 respectively.

The error will occur on the 10th declaration.

Answered by VaiStardom in 770405022

Resolution: use Group as reported by a medium article entitled Getting an "Extra Argument in Call" SwiftUI Error? Here’s How to Resolve This Bug. Quoting the article: "Containers in SwiftUI are like boxes with a limited content size, but each box is magical and counts just as a single unit, pretty cool, right? It means that no matter the internal content, each view can be placed inside another counting as only one, so each View can hold 10 direct subviews no matter what they are. Thinking about that, Group is a SwiftUI view that is made for holding some other views inside. "

Accepted Answer

Resolution: use Group as reported by a medium article entitled Getting an "Extra Argument in Call" SwiftUI Error? Here’s How to Resolve This Bug. Quoting the article: "Containers in SwiftUI are like boxes with a limited content size, but each box is magical and counts just as a single unit, pretty cool, right? It means that no matter the internal content, each view can be placed inside another counting as only one, so each View can hold 10 direct subviews no matter what they are. Thinking about that, Group is a SwiftUI view that is made for holding some other views inside. "

A bit more info from the article:

The problem is that Swift doesn't allow you to place more than ten elements within a SwiftUI container, may it be a VStack , HStack , Group , Button or whatever. This is made aiming reusability and readability across your code. If you have too many elements in a single View , it may become hard to read and solve some UI bug. So Apple highly encourages you to take some of your inner views and keep them inside another container, or maybe a new custom View .

Limit of the number of ImmersiveSpace ids?
 
 
Q