I'm trying to set up an event tap in swift using CGEventTapCreate(...)
. This takes a CGEventTapCallback
function pointer as one of its arguments.
As far as I'm aware, there's no way to pass a swift function as a c function pointer in the current beta.
What I did instead was write the callback in Objective C, as usual:
// callback.h
CGEventRef callback(CGEventTapProxy proxy, CGEventType type, CGEventRef event,
void *refcon);
// callback.m
CGEventRef callback(CGEventTapProxy proxy, CGEventType type, CGEventRef event,
void *refcon)
{
return NULL;
}
and then add the import to my bridging header:
// project-Bridging-Header.h
#import "callback.h"
This correctly exposes the function to swift. However, it does so by converting the type of the function to a swift func.
As a result, I still can't provide it as an argument to CGEventTapCreate(...)
Is there an inbuilt function which will transform a bridged function to a function pointer?