如何在Swift中传递C回调?考虑以下示例:
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) // ... } }
使用Swift 2.0,现在可以在纯Swift中设置回调了!请检查http://oleb.net/blog/2015/06/c-callbacks-in- swift/和Swift2无法调用类型类型为参数的’FSEventStreamCreate’