title: Swift: how to pass a value received from delegate to a function's completion block?
body: <p>I am trying to capture an image with AVFoundation in Swift 4.2
  The capture function lives inside a CameraEngine class that serves basically to setup the camera. So that in my VC, I can just do cameraEngine.setup() and everything is done for us.
  Here's the capture function:</p>
  <pre><code>class CameraEngine: NSObject {
  
  private var capturedImageData: Data?
  ...
  
      func captureImage() {
          let settings = AVCapturePhotoSettings()
          photoOutput?.capturePhoto(with: settings, delegate: self)
          print(capturedImageData)
      }
  
  ...
  
  }
  extension CameraEngine: AVCapturePhotoCaptureDelegate {
      func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
          self.capturedImageData = photo.fileDataRepresentation()
      }
  }
  
  </code></pre>
  <p>The question is, how can I pass the value received by the delegate to the function and back to the VC via completion handler?</p>
  <p>And called on my VC like this
  <code>cameraEngine.captureImage()</code></p>
  <p>I was hoping to get the data back so that I can manipulate it from my VC.</p>