How do you pass a C callback in Swift? Consider this example:
class AudioQueue {
var desc : AudioStreamBasicDescription
var queue : AudioQueue?
func audioQueueHandleBuffer(ctx : UnsafeMutablePointer<()>,
inAQ : AudioQueue!,
inBuffer : AudioQueueBufferRef) {
// do stuff
}
func initialize() {
// this does not work!
var err = AudioQueueNewOutput(&desc, audioQueueHandleBuffer,
nil, nil, nil, 0, queue)
// ...
}
}
With Swift 2.0 it is now possible to set up the callback in pure Swift! Please check http://oleb.net/blog/2015/06/c-callbacks-in-swift/ and Swift 2 Cannot invoke 'FSEventStreamCreate' with an argument list of type for inspiration :)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments