Method cannot be called from ViewController file into a swift file(DELEGATE)

I am totally new in swift, so if I am asking a stupid question I apologise in advance :)

I want to call my "didOutput" method from ViewController in my SampleHandler swift file. Please see the attachments below for swift files,( I just kept the related code parts in the attachments) :

When I am debugging, my code comes till delegate?.didOutput(pixelBuffer: imagePixelBuffer) line in SampleHandler.swift file but it does not pass to didOutput method in ViewContoller.swift file. Am I doing something wrong when I am implementing or declaring delegate classes and methods?

Thanks a lot in advance.

Best Regards

PS: This is my folder structure, I tried to add as screenshot but it did not work. So my files are under different folders:

ReplayKitExample ->project

    ReplayKitExample ->folder
          ViewController.swift

    BroadcastExtension->folder
           SampleHandler.swift

So my files are under different folders

Do you mean Xcode folders ?

When I am debugging, my code comes till delegate?.didOutput(pixelBuffer: imagePixelBuffer) line in SampleHandler.swift file but it does not pass to didOutput method in ViewContoller.swift file

Check that delegate is not nil:

      // Delegates the pixel buffer to the ViewController.
      print("delegate", delegate)
      delegate?.didOutput(pixelBuffer: imagePixelBuffer)

Could you also add a print here:

  func didOutput(pixelBuffer: CVPixelBuffer) {
    print(#function)
    runModel(onPixelBuffer: pixelBuffer)
  }

Check that delegate is not nil: 2.1. you are right, it is nil. I set a breakpoint to "delegate?.didOutput(pixelBuffer: imagePixelBuffer)" line and debugger showed me following output: delegate BroadcastEx

    extension ViewController: SampleHandlerDelegate {

is defined within the class.

Try to move it outside.

You should check your Target Memberships. But I did not investigate enough to say if it's OK or not.

I solved the problem my self. With the reason that it was a communication between extension and my main app, I used UserDefaults to send the variables from SampleHandler to viewContoroller instead of calling a method.

Thanks a lot for your support Claude31

Method cannot be called from ViewController file into a swift file(DELEGATE)
 
 
Q