How to convert an array to UnsafeMutablePointer <UnsafeRawPointer?> Swift 3.0?
Here is my workable code in a previous version of Swift:
let imageOptionsDictKeys = [ kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey, kCVPixelBufferIOSurfacePropertiesKey] let imageOptionsDictValues = [ cvPixelFormatType, frameW, frameH, boolYES] var keyCallbacks = kCFTypeDictionaryKeyCallBacks var valueCallbacks = kCFTypeDictionaryValueCallBacks let imageOptions = CFDictionaryCreate(kCFAllocatorDefault, UnsafeMutablePointer(imageOptionsDictKeys), UnsafeMutablePointer(imageOptionsDictValues), 4, &keyCallbacks, &valueCallbacks) After the changes in Swift 3.0, I need to convert my keys and arrays of values ββto UnsafeMutablePointer<UnsafeRawPointer?> To create a CFDictionary.
In this way:
let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1) imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeys) gives the "Bad Access" error.
And after reading the documentation, I try to compile this code:
let imageOptionsDictKeys = [kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey] let imageOptionsDictKeysRawPointer = Unmanaged.passUnretained(imageOptionsDictKeys).toOpaque() let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1) imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeysRawPointer) let imageOptionsDictValues = [ cvPixelFormatType, frameW, frameH, boolYES] let imageOptionsDictValuesRawPointer = Unmanaged.passUnretained(imageOptionsDictValues).toOpaque() let imageOptionsDictValuesPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1) imageOptionsDictValuesPointer.initialize(to: imageOptionsDictValuesRawPointer) let imageOptions = CFDictionaryCreate(kCFAllocatorDefault, imageOptionsDictKeysPointer, imageOptionsDictValuesPointer, 4, &keyCallbacks, &valueCallbacks) but the error General Instance parameter cannot be displayed. displayed in Unmanaged .passUnretained (array) .toOpaque () lines
I have no idea how to create CFDictionary programmatically now.
I just solved a similar problem of converting arrays to UnsafeMutablePointer< UnsafeMutablePointer<T>> , which you can find here: Swift 3 UnsafeMutablePointer initialization for floating type C **
To convert fast arrays using the same scheme, use UnsafeMuTablePointer as suggested here: http://technology.meronapps.com/2016/09/27/swift-3-0-unsafe-world-2/