I've a problem with accessing a specific (or any) key in a CFDictionary. Honestly I don't really get the way you need to do this in Swift and I think it's overly complicated...
My Code:
if let session = DASessionCreate(kCFAllocatorDefault) {
let mountedVolumes = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: [], options: [])!
for volume in mountedVolumes {
if let disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, volume as CFURL) {
let diskinfo = DADiskCopyDescription(disk);
var volumeValue = CFDictionaryGetValue(diskinfo, <#T##key: UnsafeRawPointer!##UnsafeRawPointer!#>)
}
}
What I want to achieve: Get the Value for the Key or field DAVolumeNetwork into the variable volumeValue. I guess I need to pass the kDADiskDescriptionVolumeNetworkKey to the CFDictionaryGetValue Method? How do I achieve this?
Don't use
CFDictionaryin Swift. (It is possible, but not worth the effort, see below.)CFDictionaryis toll-free bridged withNSDictionary, which in turn can be cast to a SwiftDictionary.kDADiskDescriptionVolumeNetworkKeykey is aCFBooleanwhich can be cast to a SwiftBool.Example:
Just for the sake of completeness: This is the necessary pointer juggling to call
CFDictionaryGetValuein Swift 3: