JUL*_*ito 6 unsafe-pointers ios swift swift3 unsafemutablepointer
这是我在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)
Run Code Online (Sandbox Code Playgroud)
在Swift 3.0中进行更改后,我必须将我的键和值数组转换UnsafeMutablePointer<UnsafeRawPointer?>为创建CFDictionary.
这条路:
let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1)
imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeys)
Run Code Online (Sandbox Code Playgroud)
出现错误访问错误.
在阅读文档后,我正在尝试编译此代码:
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)
Run Code Online (Sandbox Code Playgroud)
但错误 通用参数'Instance'无法推断出现在Unmanaged.passUnretained(array).toOpaque()行中
我现在不知道如何以编程方式创建CFDictionary.
Ars*_*hia -1
我刚刚解决了一个类似的问题,将数组转换为UnsafeMutablePointer< UnsafeMutablePointer<T>>您可以在这里找到的:
Swift 3 UnsafeMutablePointer optimization for C type float**
要使用相同的方案转换 swift 数组,请UnsafeMuTablePointer按照此处的建议使用:http ://technology.meronapps.com/2016/09/27/swift-3-0-unsafe-world-2/
| 归档时间: |
|
| 查看次数: |
4015 次 |
| 最近记录: |