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

半城伤御伤魂 提交于 2019-12-30 11:12:14

问题


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.


回答1:


@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!



来源:https://stackoverflow.com/questions/24356009/swift-error-use-of-module-cmsamplebuffer-as-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!