根据文档 CFDictionaryCreate
用于实例化 CFDictionary 中的swift
.
func CFDictionaryCreate(_ allocator: CFAllocator!,
_ keys: UnsafeMutablePointer<UnsafePointer<Void>>,
_ values: UnsafeMutablePointer<UnsafePointer<Void>>,
_ numValues: CFIndex,
_ keyCallBacks: UnsafePointer<CFDictionaryKeyCallBacks>,
_ valueCallBacks: UnsafePointer<CFDictionaryValueCallBacks>) -> CFDictionary!
如何创建keys
andvalues
参数?到目前为止,我尝试使用 swift 的String
类型,希望它能自动转换为适当的类型:
import Foundation
var keys : [String] = ["key1", "key2"]
var values : [String] = ["value1", "value2"]
var keyCallbacks = kCFTypeDictionaryKeyCallBacks
var valueCallbacks = kCFTypeDictionaryValueCallBacks
var dict : CFDictionary = CFDictionaryCreate(kCFAllocatorDefault,
&keys, &values, 2, &keyCallbacks, &valueCallbacks)
不幸的是,我收到一条错误消息,说不是String
数组元素的正确类型:keys
values
main.swift:41:2: error: 'String' is not identical to 'UnsafePointer<Void>'
&configKeys, &configValues, 3, &keyCallbacks, &valueCallbacks)
我怎么做UnsafePointer<Void>
?String