这是我在Swift的早期版本中可行的代码:
bar
在Swift 3.0中进行更改后,我必须将我的键和值数组转换为 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)
以创建CFDictionary。
这样:
UnsafeMutablePointer<UnsafeRawPointer?>
发出错误访问错误。
在阅读文档后,我正在尝试编译此代码:
let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1)
imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeys)
但错误通用参数&#39;实例&#39;无法推断出现在 Unmanaged.passUnretained( array )。toOpaque()
行中我现在不知道如何以编程方式创建CFDictionary。
答案 0 :(得分:0)
我刚刚解决了将数组转换为UnsafeMutablePointer< UnsafeMutablePointer<T>>
的类似问题,您可以在此处找到:
Swift 3 UnsafeMutablePointer initialization for C type float**
要使用相同的方案转换swift数组,请按照此处的建议使用UnsafeMuTablePointer
:http://technology.meronapps.com/2016/09/27/swift-3-0-unsafe-world-2/