Posts

Post marked as solved
2 Replies
643 Views
Hello!I am trying to write an application for macOS. I am using Cocoa and Swift and targeting macOS 10.13.My goal is to open a USB HID device. I am using IOKit.hidSummary of issue:let devices = IOHIDManagerCopyDevices(manager) if (devices != nil) { var refs =<unsaferawpointer?> UnsafeMutablePointer<unsaferawpointer?>.allocate(capacity: CFSetGetCount(devices)) CFSetGetValues(devices, refs) var deviceHandle = refs![0] }IOHIDManagerCopyDevices(...) gives me a CFSetRefI unpack the CFSetRef using CFSetGetValues(...); the second argument is of type UnsafeMutablePointer<UnsafeRawPointer?>?Now, I want to get the first item, call it deviceHandledeviceHandle is of type UnsafeRawPointer? ........ but I want an IOHIDDevice😟I'm still very new to development for Apple platforms so please let me know if I'm missing anything obviousBut I'm stumped as to how to convert my UnsafeRawPointer? to an IOHIDDevice.The below gives me an EXC_BAD_INSTRUCTION (EXC_I386_INVOP):var test = deviceHandle as! IOHIDDeviceI have already confirmed that the pointer's _rawValue is correct by comparing with another implementation using IOHIDManagerRegisterDeviceMatchingCallback(), but I would prefer to do this synchronouslyIs there an easy way to convert my UnsafeRawPointer? to IOHIDDevice?ThanksKevin
Posted
by kedxu.
Last updated
.