【发布时间】:2019-12-23 17:08:56
【问题描述】:
我在 Objective-C 中发现了一个从 Getting graphic card information in objective C 截取的代码,我目前正在尝试将其转换为 Swift。
我正在尝试从CFMutableDictionary 中读取一个值(代码如下)。但是,当我调用函数CFDictionaryGetValue 时,我得到一个错误:
“线程 1:EXC_BAD_ACCESS(代码=1,地址=0x656d614e4f60)”
这是我当前的代码:
static func getGpuName() {
var iterator: io_iterator_t = 0
let errCode: kern_return_t = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOPCIDevice"), &iterator)
if errCode != kIOReturnSuccess {
fatalError("Could not retrieve the service dictionary of \"IOPCIDevice\"")
}
// iterate over the pci devices
var device = IOIteratorNext(iterator)
while device != 0 {
var unmanagedServiceDictionary: Unmanaged<CFMutableDictionary>?
if IORegistryEntryCreateCFProperties(device, &unmanagedServiceDictionary, kCFAllocatorDefault, 0) != kIOReturnSuccess {
IOObjectRelease(device)
continue
}
if let serviceDictionary: CFMutableDictionary = unmanagedServiceDictionary?.takeRetainedValue() {
let name = CFDictionaryGetValue(serviceDictionary, "IOName")
}
// release the device
IOObjectRelease(device)
// get the next device from the iterator
device = IOIteratorNext(iterator)
}
}
有人知道我如何读取CFMutableDictionary 的值吗?
谢谢:)
【问题讨论】:
标签: objective-c swift macos core-foundation