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
- initial scene of
- in
App
file, under body, copy paste the ImmersiveSpace block 10 times, renaming the id'sImmersiveSpace1
through toImmersiveSpace10
respectively.
The error will occur on the 10th declaration.
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. "