gpt4 book ai didi

swift - 在 Swift 中,如何将 CFStringRef[] 和 CFTypeRef[] 转换为 CMutablePointer< COpaquePointer >?

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

在 Swift 中我如何转换 CFStringRef[]CFTypeRef[]CMutablePointer< COpaquePointer >

我想调用CFDictionaryCreate来自 swift 。我已经定义:

var keys: CFStringRef[] = [kCGImageSourceCreateThumbnailWithTransform, kCGImageSourceCreateThumbnailFromImageIfAbsent, kCGImageSourceThumbnailMaxPixelSize, kCGImageSourceCreateThumbnailFromImageAlways]

var values: CFTypeRef[] = [kCFBooleanTrue, kCFBooleanTrue, imageSize, kCFBooleanTrue]

CFDictionaryCreate(nil, keys, values, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)

但不知道如何在上述调用中指定键和值。

最佳答案

我可以通过为您创建不安全的指针让编译器停止提示,但我对 CFDictionary 的其余用法超出了我的理解范围。

import ImageIO

let dictionayKeyCB = UnsafePointer<CFDictionaryKeyCallBacks>()
let valueKeyCB = UnsafePointer<CFDictionaryValueCallBacks>()

let keys: [CFStringRef] = [kCGImageSourceCreateThumbnailWithTransform, kCGImageSourceCreateThumbnailFromImageIfAbsent, kCGImageSourceThumbnailMaxPixelSize, kCGImageSourceCreateThumbnailFromImageAlways]
let keysPointer = UnsafeMutablePointer<UnsafePointer<Void>>.alloc(1)
keysPointer.initialize(keys)

let values: [CFTypeRef] = [kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue]
let valuesPointer = UnsafeMutablePointer<UnsafePointer<Void>>.alloc(1)
valuesPointer.initialize(values)

CFDictionaryCreate(kCFAllocatorDefault, keysPointer, valuesPointer, 4, dictionayKeyCB, valueKeyCB)

关于swift - 在 Swift 中,如何将 CFStringRef[] 和 CFTypeRef[] 转换为 CMutablePointer< COpaquePointer >?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24188101/

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