Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
ARKit camera tracking state can’t show on SwiftUI

I’m trying to show the camera tracking state info on top of device screen, but still get errors for all my efforts. I’m very confused with how ARView works with SwiftUI, for showing AR experience and adding button icons on top of it is simple, but to getting data from session just looks more work need to be done, could someone help me this? Thanks!

Error in ViewModel: ‘description is a get-only property’

Content View

import SwiftUI
import ARKit
import RealityKit

struct ContentView: View {
    @StateObject var vm = ViewModel()
    
    var body: some View {
        ZStack{
            ARViewContainer()
                .edgesIgnoringSafeArea(.all)
                .environmentObject(vm)
            VStack{
                Text(vm.sessionInfoLabel)
                    .font(.title3)
                    .foregroundColor(.red)
                
                Spacer()
                HStack{
                    Button{
                        
                    } label: {
                        Image(systemName: "person.2")
                            .padding()
                            .font(.title)
                    }
                    Spacer()
                    Button{
                        
                    } label: {
                        Image(systemName: "target")
                            .padding()
                            .font(.title)
                    }
                }
                .padding()
                
            }
        }
    }
}

struct ARViewContainer: UIViewRepresentable {
    @EnvironmentObject var vm: ViewModel
    func makeUIView(context: Context) -> ARView {
        return vm.arView
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {
    }
}

ViewModel

import SwiftUI
import ARKit
import RealityKit

class ViewModel: ObservableObject {
    @Published var arView: ARView
    var sessionInfoLabel = ""
    init() {
        arView = ARView.init(frame: .zero)
        let config = ARWorldTrackingConfiguration()
        config.planeDetection = .horizontal
        arView.session.delegate = arView
        arView.session.run(config)
    }
}


extension ARView: ARSessionDelegate {
    public func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera) {
        camera.trackingState.description = ViewModel().sessionInfoLabel
    }
}

extension ARCamera.TrackingState: CustomStringConvertible {
    public var description: String {
        switch self {
        case .normal:
            return "Normal"
        case .notAvailable:
            return "Not Available"
        case .limited(.initializing):
            return "Initializing"
        case .limited(.excessiveMotion):
            return "Excessive Motion"
        case .limited(.insufficientFeatures):
            return "Insufficient Features"
        case .limited(.relocalizing):
            return "Relocalizing"
        case .limited:
            return "Unspecified Reason"
        }
    }
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!