How to convert CMSampleBuffer to Mat in iOS and Swift

I am writing an iPhone app that does some sort of real-time image detection with OpenCV. What is the best way to convert a CMSampleBuffer image from the camera (I’m using AVCaptureVideoDataOutputSampleBufferDelegate of AVFoundation) into a Mat that OpenCV understands