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
?
For Swift 3 you need extra casting to CFDictionary
.
Otherwise Contextual type 'CFDictionary' cannot be used with dictionary literal is thrown.
let options: CFDictionary = [kSecImportExportPassphrase as String : "certificateKey"] as CFDictionary
See https://bugs.swift.org/browse/SR-2388 for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With