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?
What about something like:
If you don't have to deal with other Core Foundation functions expecting an
CFDictionary
, you can simplify it by converting to Swift nativeDictionary
:Be careful converting a
CFDictionary
to a Swift native dictionary. The bridging is actually quite expensive as I just found out in my own code (yay for profiling!), so if it's being called quite a lot (as it was for me) this can become a big issue.Remember that
CFDictionary
is toll-free bridged withNSDictionary
. So, the fastest thing you can do looks more like this:You can write something like this:
But I guess you would not like to write such thing at any time you retrieve some data from that
CFDictionary
. You better convert it to SwiftDictionary
as suggested in Code Different's answer.