Can't create ARView for non AR application

Hi all, I'm trying to create a simple 3d application using RealityKit but for some reason in XCode project this code yield error

let arView = ARView(frame: .zero, cameraMode: .nonAR, automaticallyConfigureSession: true)

saying :

  • Cannot infer contextual base in reference to member 'nonAR'
  • Extra arguments at positions #2, #3 in call

Basically suddenly the project won't except the other way to initialize ARView. This is confusing because I tried on Swift Playground and it works fine!

I've tried updating my XCode, clean install and even tried on several macbooks but still the same. Looking up at the documentation and there doesn't seem any information regarding this being deprecated or changed.

So here's a funny thing, this code totally works on Swift Playground for Mac but it doesn't work on Playground on XCode :

import PlaygroundSupport

import RealityKit

let arView = ARView(frame: .zero, cameraMode: .nonAR, automaticallyConfigureSession: true)

let point = PointLight()
point.light.intensity = 1000
let lightAnchor = AnchorEntity(world: [0,0,0])
lightAnchor.addChild(point)
arView.scene.addAnchor(lightAnchor)

let textMesh = MeshResource.generateSphere(radius: 0.5)
 let material = SimpleMaterial(color: .white, isMetallic: false)
 let entity = ModelEntity(mesh: textMesh, materials: [material])

 let anchor = AnchorEntity(world: [0,0.25,0])
 anchor.addChild(entity)
 arView.scene.addAnchor(anchor)

 let camera = PerspectiveCamera()
 let camAnchor = AnchorEntity(world: [0,0,5])
 camAnchor.addChild(camera)
 arView.scene.addAnchor(camAnchor)

PlaygroundPage.current.setLiveView(arView)

Help?? Any idea?

The doc says that init(frame:cameraMode:automaticallyConfigureSession:) is only available for iOS 13+, no macOS. Are you sure you made the project for iOS?

I would suggest you create your ARView by only passing in the frame variable to the constructor. cameraMode and automaticallyConfugureSession can be set on the ARView afterwards. I think cameraMode is only available on certain platforms so you can ifdef that specific line out if needed.

Can't create ARView for non AR application
 
 
Q