Instance member cannot be used on type in ARKitVision example

The Apple ARKitVision example has the following declaration in the ViewController.swift file:


// The view controller that displays the status and "restart experience" UI.

private lazy var statusViewController: StatusViewController = {

return children.lazy.compactMap({ $0 as? StatusViewController }).first!

}()


However, if I copy the same views and source files and incorporate them into another test storyboard/project I get the error message "Instance member 'children' cannot be used on type 'StatusViewController'". So, why does this work on the ARKitVision example but it does not work if I set it up myself from scratch? What else is the ARKitVision example doing to get this working? Thanks 😊

I don't understand, the class inherits from UIViewController and yet Xcode does not see the 'children' var as being available. Why would that be the case?

How did you define StatusViewController ? Did you import the class definition as well ?

Do you have "Embed segue to status view controller" in your View Controller Scene?

It inherits from StatusViewController which inherits from UIViewController.

Yes, I imported the StatusViewController class and it too subclasses UIViewController.

Yes, I have "Embed segue to status view controller" in my View Controller Scene.


Both ViewController and StatusViewController subclass UIViewController. In the ARKitVision ViewController.swift class if I start typing "children" it recognises it as a var that can be used. If I go to my own project with exactly the same classes, exactly the same code and start typing "children" it does not recognise it as a var that can be used. If I delete the "private lazy var statusViewController: StatusViewController" declaration the code compiles and runs perfectly. I can also programmatically create the StatusViewController. For some unexplained reason, even though I have subclassed UIViewController, used exactly the same code as in ARKitVision, my subclass cannot gain access to the parents variables, and hence displays the above message.

Instance member cannot be used on type in ARKitVision example
 
 
Q