简体   繁体   中英

Swift Error : Use of module 'CMSampleBuffer' as a type

I saw below question to use 'captureStillImageAsynchronouslyFromConnection' function in swift: How to convert code AVFoundation objective c to Swift?

When I try to use a AVFoundation function as following:

var stillImageOutput: AVCaptureStillImageOutput!

//...Initialize stillImageOutput

stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(imageSampleBuffer, error) in
        if imageSampleBuffer {
            var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer as CMSampleBuffer) // I get error on this line saying: 'Use of module ' CMSampleBuffer' as a type'
            self.processImage(UIImage(data: imageData))
        }
        })

I got the error on XCode, which says 'Use of module ' CMSampleBuffer' as a type'. I tried to rewrite that same line multiple times with slightly different ways, but I could not figure out the solution.

Am I doing something wrong or is it possibly the shaky XCode Beta not working properly?

Thank you in advance.

@Jack and @Christian's solutions worked for me. I was not careful enough to import CoreMedia . I never used this framework before, and did not know if the problem was due to not having imported a correct framework. Thank you for your help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM