Group Group Group Group Group Group Group Group Group

Chapter 10: Value of type 'ARView' has no member 'session'

Am unable to compile code for Chapter 10.

First of all, in the book it’s written to add some code to updateView(_:context:) as follows:

However there’s only updateUIView function available. When looking at the final project implementation the later is used.

The error message I get when I add

uiView.session.run(arConfiguration, 
  options:[.resetTracking, .removeExistingAnchors])

to updateUIView:

Code that I have:

import ARKit
import SwiftUI
import RealityKit

var arView: ARView!

struct ContentView : View {
    @State var propId: Int = 0
    
    func TakeSnapshot() {
        arView.snapshot(saveToHDR: false) { (image) in
            let compressedImage = UIImage(data: (image?.pngData())!)
            UIImageWriteToSavedPhotosAlbum(compressedImage!, nil, nil, nil)
        }
    }
    
    var body: some View {
        ZStack(alignment: .bottom) {
            ARViewContainer(propId: $propId).edgesIgnoringSafeArea(.all)
            HStack {
                Spacer()
                Button(action: {
                    self.propId = self.propId <= 0 ? 0 : self.propId - 1
                }){
                    Image("PreviousButton").clipShape(Circle())
                }
                
                Spacer()
                Button(action: {
                    self.TakeSnapshot()
                }){
                    Image("ShutterButton").clipShape(Circle())
                }
                
                Spacer()
                Button(action: {
                    self.propId = self.propId >= 2 ? 2 : self.propId + 1
                }){
                    Image("NextButton").clipShape(Circle())
                }
                Spacer()
            }
        }
    }
}

struct ARViewContainer: UIViewRepresentable {
    @Binding var propId: Int
    
    func makeUIView(context: Context) -> ARView {
        arView = ARView(frame: .zero)
        return arView
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {
        let arConf = ARFaceTrackingConfiguration()
        uiView.session.run(arConf, options: [.resetTracking, .removeExistingAnchors])
        
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Any help would be appreciated in fixing this issue.

The solution is not to use iOS simulator when building as per https://stackoverflow.com/a/56982390