According to documentation CFDictionaryCreate is used to instantiate CFDictionary in swift.
func CFDictionaryCreate(_ allocator: CFAllocator!,
_ keys: UnsafeMutablePointer<UnsafePointer<Void>>,
_ values: UnsafeMutablePointer<UnsafePointer<Void>>,
_ numValues: CFIndex,
_ keyCallBacks: UnsafePointer<CFDictionaryKeyCallBacks>,
_ valueCallBacks: UnsafePointer<CFDictionaryValueCallBacks>) -> CFDictionary!
How can I create the keys and values arguments?
So far I've tried to use swift's String type hoping it would be automatically converted to appropriate types:
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)
Unfortunately I receive an error saying String is not the right type for keys and values array elements:
main.swift:41:2: error: 'String' is not identical to 'UnsafePointer<Void>'
&configKeys, &configValues, 3, &keyCallbacks, &valueCallbacks)
How do I make an UnsafePointer<Void> from String?
rintaro's comment worked for String literals, but not when I was working with a
CFStringRefand a SwiftString:I had to cast the CFStringRef as a Swift String: