How to connect AVCaptureVideoDataOutput to AVCaptureVideoPreviewLayer

In the attached picture, the presenter is implying that a video data output can be associated with a video preview layer. I don't see an explicit way to make such an association happen. Can someone drop sample code here or point to me to relevant documentation?

From what I have gathered so far, a AVCaptureConnection can only be created between a video input port to a preview layer but that doesn't allow us to gain any of the benefits outlined in the presentation.

Thanks

Hello, you can find an example of the implementation on the Apple Developer Documentation here: https://developer.apple.com/documentation/avfoundation/capture_setup/setting_up_a_capture_session/.

If you scroll down you should be able to find the Display A Camera Preview section. Here is the example code:

class PreviewView: UIView {
    override class var layerClass: AnyClass {
        return AVCaptureVideoPreviewLayer.self
    }
    
    /// Convenience wrapper to get layer as its statically known type.
    var videoPreviewLayer: AVCaptureVideoPreviewLayer {
        return layer as! AVCaptureVideoPreviewLayer
    }
}
self.previewView.videoPreviewLayer.session = self.captureSession
How to connect AVCaptureVideoDataOutput to AVCaptureVideoPreviewLayer
 
 
Q