ios - Implementing a c function callback in Swift 2.0? -


cfreadstreamsetclient has c-function callback (cfreadstreamclientcallback) in it's initializer,

cfreadstreamclientcallback looks this:

typealias cfreadstreamclientcallback = (cfreadstream!,         cfstreameventtype, unsafemutablepointer<void>) -> void 

i have method attempts handle cfreadstreamclientcallback c-function callback:

func callback(stream: cfreadstreamref,         eventtype: cfstreameventtype,         inclientinfo: unsafemutablepointer<void>) {     } 

but when attempt set callback in cfreadstreamcallback follows, doesn't compile.

cfreadstreamsetclient(stream, registeredevents, callback, clientcontextptr)

i know swift 2.0 there's way use swift closures c-function callbacks cant seem work. know how can done in situation?

you can make closure in function this:

cfreadstreamsetclient(stream, registeredevents, { readstream, event, data -> void in      // stuff here. }, clientcontextptr) 

also note c function blocks can't have context can't access self, or other variable outside block. if doesn't work can include compiler error in question?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -