3

I am currently working on a project that uses a live camera view in Swift. I used some code I found on GitHub to give me that live camera view, and it works great on my MacBook Pro running Mojave. I have all my files stored on an external HDD, so I went to my iMac and started working on the project there. I think I have two different versions of the Xcode 10 beta, which could be part of the problem? Basically this line works fine on my MacBook but not on that iMac, which btw is running macOS high Sierra version 15:

guard let pixelBuffer : CVPixelBuffer = sampleBuffer.imageBuffer else { return }

It gives me the following error:

Value of type 'CMSampleBuffer' has no member 'imageBuffer'

But when opening the exact same project on my macbook this works with no problems whatsoever. Could this be an Xcode version thing or is it because I am running two different macOS version?

Thijs van der Heijden
  • 1,147
  • 1
  • 10
  • 25
  • 1
    There is no `imageBuffer` property in any class in iOS. Where are you getting that from? Must be your own or some 3rd party extension. – rmaddy Jul 06 '18 at 17:11
  • Hi, actually when I jump to the definition of imageBuffer, I end up in the coreMedia file for CMSampleBuffer which has the following code: `@available(iOS 4.0, *) public var imageBuffer: CVImageBuffer? { get }` But on my iMac which is running an older version of macOS, but a newer version of the xcode 10 beta, there is no definition for imageBuffer? – Thijs van der Heijden Jul 07 '18 at 19:56
  • The only references to `imageBuffer` I see is as parameters to a couple of functions. – rmaddy Jul 07 '18 at 20:04

2 Answers2

9

You can still use this function:

CMSampleBufferGetImageBuffer(_ sbuf: CMSampleBuffer) to get a CVPixelBuffer?.

The direct replacement would be:

guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
kuhncj
  • 236
  • 2
  • 10
0

I have the same issue with a code base that worked on one MacBook but not on another. The working MacBook is with Apple for repair so I cannot Validate versions although I do know my working code from it uses CMSampleBufferGetImageBuffer. On my backup, it says this has been replaced by CMSampleBuffer.imageBuffer in swift 4.2 which doesn’t exist. It’s using Mojave, Xcode 10 beta 3 and ios12.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Wozzer
  • 73
  • 1
  • 1
  • 5