Here's a solution (possibly far from perfect) that works with Swift 4 (should work with 3).
func setSampleBufferAttachments(_ sampleBuffer: CMSampleBuffer) {
let attachments: CFArray! = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true)
let dictionary = unsafeBitCast(CFArrayGetValueAtIndex(attachments, 0),
to: CFMutableDictionary.self)
let key = Unmanaged.passUnretained(kCMSampleAttachmentKey_DisplayImmediately).toOpaque()
let value = Unmanaged.passUnretained(kCFBooleanTrue).toOpaque()
CFDictionarySetValue(dictionary, key, value)
}
source
share