J'ai un programme sur HID. Mais il est écrit en Objective-C. C'est un projet et mes amis ne savent que vite. J'ai donc pensé à le convertir en rapide et je n'arrive pas à comprendre comment écrire cette fonction.Comment écrire la fonction HID Handle_DeviceMatchingCallback dans swift?
code Obj-c:
/* Creating The HID Manager */
IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
/* Dictionary Matching - All the devices */
IOHIDManagerSetDeviceMatching(manager,NULL);
/* Connected and Disconnected Call Backs */
IOHIDManagerRegisterDeviceMatchingCallback(manager, &Handle_DeviceMatchingCallback , NULL);
IOHIDManagerRegisterDeviceRemovalCallback(manager, &Handle_DeviceRemovalCallback,NULL);
Et l'appel sur les fonctions sont les suivantes:
static void Handle_DeviceMatchingCallback(void *inContext,
IOReturn inResult,
void *inSender,
IOHIDDeviceRef inIOHIDDeviceRef)
{
printf("Connected\n");
}
static void Handle_DeviceRemovalCallback(void *inContext,
IOReturn inResult,
void *inSender,
IOHIDDeviceRef inIOHIDDeviceRef)
{
printf("Disconnected\n");
}
En rapide,
j'ai écrit Handle_DeviceMatchingCallback()
comme
func Handle_DeviceMatchingCallback(inContext: UnsafeMutableRawPointer!, inResult: IOReturn, inSender: UnsafeMutableRawPointer!, inIOHIDDeviceRef: IOHIDDevice)
{
print("Connected")
}
Mais je ne peux pas passer la fonction à IOHIDManagerRegisterDeviceMatchingCallback()
.
Comment faire?