Search code examples
swiftswift3core-foundation

How to access CFDictionary in Swift 3?


I need to read and write some data from CFDictionary instances (to read and update EXIF data in photos). For the life of me, I cannot figure out how to do this in Swift 3. The signature for the call I want is:

func CFDictionaryGetValue(CFDictionary!, UnsafeRawPointer!)

How the heck do I convert my key (a string) to an UnsafeRawPointer so I can pass it to this call?


Solution

  • If you don't have to deal with other Core Foundation functions expecting an CFDictionary, you can simplify it by converting to Swift native Dictionary:

    if let dict = cfDict as? [String: AnyObject] {
        print(dict["key"])
    }