Is it possible to pass a closure from a Swift program into an API where the corresponding argument has been marked as CFunctionPointer
?
I've come across indications (e.g. here) that this was not possible with (by now obsolete) beta versions of Xcode 6.
However, you cannot call a C function pointer or convert a closure to C function pointer type.
Is it possible by now and if so how?
For instance, how could one define a closure in Swift that would be accepted as AudioServicesSystemSoundCompletionProc
in a call to AudioServicesAddSystemSoundCompletion
?
This answer employs both Swift and Objective-C to arrive at a solution. Is one possible with a Swift class alone?