我有一个像
这样的课程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
}
}
我收到错误A C function pointer can only be formed from a reference to a 'func' or a literal closure
所以我试着写出像
这样的闭包let Handle_DeviceMatchingCallback: IOHIDDeviceCallback = {context, result, sender, device in
connectedDeviceList.append(String(describing: device))
print("Connected")
connectedData()
}
现在我在Instance member cannot be used on type 'Main'
和connectedData()
connectedDeviceList
当我删除那些实例变量和方法时,没有错误,但我需要实现该方法。
我该如何解决这个问题?