CGEventTapCallBack needs to return NULL

The documentation for CGEventTapCallBack says to return NULL if an event is to be deleted otherwise to return Unmanged<CGEvent>.

I have an Objective-C app that uses this feature and I am converting it to Swift using Xcode 9.3.1


The current Swift documentation of CGEventTapCallBack says


If the event tap is an active filter, your callback function should return one of the following:

  • The (possibly modified) event that is passed in. This event is passed back to the event system.
  • A newly-constructed event. After the new event has been passed back to the event system, the new event will be released along with the original event.
  • NULL
    if the event passed in is to be deleted.


How do I accomplish this NULL return value in Swift which is looking for a CGEvent?

Replies

I do not understand what part you think is difficult. Just return `nil` when `NULL` is appropriate for the return value.


If this cannot be any help of you, please clarify what you think is difficult. Showing your Objective-C code and its translated code into Swift would be a good way.

I tried returning NULL and 0 but I did not try returning nil.

That did the trick. Thank you.