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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World