gpt4 book ai didi

ios - 如何将数组转换为 UnsafeMutablePointer Swift 3.0?

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:27 25 4
gpt4 key购买 nike

这是我在以前版本的 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?>用于创建 CFDictionary。

这样:

    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)

但错误Generic parameter 'Instance' could not be inferred 出现在 Unmanaged.passUnretained(array).toOpaque() 行中/p>

我现在不知道如何以编程方式创建 CFDictionary。

最佳答案

我刚刚解决了将数组转换为 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/

关于ios - 如何将数组转换为 UnsafeMutablePointer<UnsafeRawPointer?> Swift 3.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39965810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com