Using callback function in C app with swift library

I have a C app on MacOS and I call functions in a swift dylib. I want to register callback functions in C to be called in swift when some event happens. Is there some example on how to do this?

I have this callback declaration in C:
typedef int (*event_cb_t)(int evt, char *data);

I want to register the callback in swift like this:
//callback function defined in C
int callback(int evt, char *data)
{
return 0;
}

registerCb(callback); //swift exported function

AFAIK things haven’t changed since this thread.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Hey, i just did a answer into this same question but with C++. I have pointed a possible solution there and i think it can work for your case too.

I hope it helps.