如何将数组转换为UnsafeMutablePointer <UnsafeRawPointer?> Swift 3.0?
这是我以前版本的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)
在Swift 3.0中进行更改后,我必须将我的键和值数组转换为UnsafeMutablePointer<UnsafeRawPointer?>
来创buildCFDictionary。
这条路:
let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1) imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeys)
给出一个错误访问错误。
阅读文档后,我试图编译这个代码:
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)
但无法推断错误通用参数“Instance”出现在行Unmanaged.passUnretained( array ).toOpaque()
我不知道如何编程现在创buildCFDictionary。
我刚刚解决了一个类似的问题,将数组转换为UnsafeMutablePointer< UnsafeMutablePointer<T>>
,您可以在这里find: Swift 3 UnsafeMutablePointer初始化C型float **
要使用相同的scheme转换swift数组, UnsafeMuTablePointer
按照以下build议使用UnsafeMuTablePointer
: http : UnsafeMuTablePointer