mercredi 1 juillet 2015

Implementing a c function callback in Swift 2.0?

CFReadStreamSetClient has a C-function callback (CFReadStreamClientCallBack) in it's initializer,

CFReadStreamClientCallback looks like this:

typealias CFReadStreamClientCallBack = (CFReadStream!,
        CFStreamEventType, UnsafeMutablePointer<Void>) -> Void

I have a method that attempts to handle the CFReadStreamClientCallBack C-function callback:

func callback(stream: CFReadStreamRef,
        eventType: CFStreamEventType,
        inClientInfo: UnsafeMutablePointer<Void>) {
    }

but when i attempt to set the callback in CFReadStreamCallback as follows, it doesn't compile.

CFReadStreamSetClient(stream, registeredEvents, callback, clientContextPtr)

I know with Swift 2.0 there's a way to use Swift closures with C-Function callbacks but I cant seem to get it to work. Does anyone know how it can be done in this situation?

Aucun commentaire:

Enregistrer un commentaire