I have a class like
class Main
{
var manager: IOHIDManager
var connectedDeviceList = [String]()
init()
{
manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
IOHIDManagerSetDeviceMatching(manager, nil)
IOHIDManagerRegisterDeviceMatchingCallback(manager, Handle_DeviceMatchingCallback, nil)
}
func Handle_DeviceMatchingCallback(_ context: UnsafeMutableRawPointer?, _ result: IOReturn, _ sender: UnsafeMutableRawPointer?, _ device: IOHIDDevice)
{
connectedDeviceList.append(String(describing: device))
print("Connected")
connectedData() // just another function
}
}
I get an error A C function pointer can only be formed from a reference to a 'func' or a literal closure
So I tried to write in closures like
let Handle_DeviceMatchingCallback: IOHIDDeviceCallback = {context, result, sender, device in
connectedDeviceList.append(String(describing: device))
print("Connected")
connectedData()
}
Now I get Instance member cannot be used on type 'Main'
on connectedData()
and connectedDeviceList
When I remove those instance variable and method, there is no error but I need to implement that method.
How can I solve this?