View variable gets instantiated twice? Class member is different from the one in body

struct CameraMain: View {
    var cameraViewController = CameraViewController()
    var body: some View {
        ZStack {
            cameraViewController // this calls viewDidLoad on another instance
            Button(action: toggleRecording)  {...} 
            }
        }
    
    func toggleRecording() {
        self.cameraViewController.startRecording()
        // this instance of cameraViewController did not call viewDidLoad !!!
    }
}

final class CameraViewController: UIViewController {
    override func viewDidLoad() {
      // initialization ...
    }
}

Hi! I would like to call methods on my cameraViewController inside toggleRecording. Somehow the instance of cameraViewController I get there is not the same one that runs viewDidLoad.

How can I access the same instance that called viewDidLoad ?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum