'onAppear for views created in a storyboard

I am using a library, which is more tailored towards Swift UI, but I am creating app based on regular Views and ViewControllers. The object for that library need to be declared(at least from my understanding) it as either @StateObject or @ObservableObject, I get the same error for both:

Accessing StateObject's object without being installed on a View. This will create a new instance each time.

From similar issues, the solution seems to be to use .onAppear(Accessing StateObject's object without being installed on a View. This will create a new instance each time - SwiftUI), but I am lost on how to call .onAppear for an @IBOutlet Is there a way to call .onAppear for a view, which is declared as:

@IBOutlet var hostView: CPTGraphHostingView!

?

UPDATE

If I declare the object as

var conductor = TunerConductor()

The Tuner Conductor errors out with the same throw in the initialization phase:

  init() {
    print("init started ")
    guard let input = engine.input else { fatalError() }

    guard let device = engine.inputDevice else { fatalError() }
    print("input selected")
    initialDevice = device

    mic = input
    tappableNodeA = Fader(mic)
    tappableNodeB = Fader(tappableNodeA)
    tappableNodeC = Fader(tappableNodeB)
    silence = Fader(tappableNodeC, gain: 0)
    engine.output = silence
    print("objects init")
    tracker = PitchTap(mic) { pitch, amp in
        DispatchQueue.main.async {
            self.update(pitch[0], amp[0])
        }
    }
    
}

Output looks like:

init started

2022-04-22 17:53:21.604952-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606254-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606352-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606437-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606514-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606606-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606685-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606764-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.606839-0700 SING[9300:646252] throwing -10878

input selected

2022-04-22 17:53:21.615502-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.615950-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616028-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616097-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616167-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616237-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616320-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616396-0700 SING[9300:646252] throwing -10878 2022-04-22 17:53:21.616471-0700 SING[9300:646252] throwing -10878

objects init

There are no mentions of this error code in the library nor in swift in general, so I am lost what can it be.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source