swift - Self as argument type of generic callback -


i'm trying implement generic broadcasting function each type supports specific protocol. example:

protocol proto {     typealias itemtype     typealias callback = (self, itemtype)      func register(tag: string, cb: callback)     func unregister(tag: string) }  class foo : proto {     typealias itemtype = int      func register(tag: string, cb: (foo, int)) {      }      func unregister(tag: string) {      } }  func bc <t: proto> (p: t, value: t.itemtype, os: [string: t.callback]) {     (k, v) in os {         v(p, value) // error: cannot invoke v argument list of...     } } 

question how implement bc function right?

i think swift buggy @ place. maybe can use

protocol proto {     typealias itemtype      func register(tag: string, cb: (self, self.itemtype)->())     func unregister(tag: string, cb: (self, self.itemtype)->()) }  class foo : proto {      func register(tag: string, cb: (foo, int)->()) {      }     func unregister(tag: string, cb: (foo, int)->()) {      } }  func bc <t: proto> (p: t, value: t.itemtype, os: [string : (t,t.itemtype)->()]) {     (_, vc) in os {         vc(p, value) // error: cannot invoke v argument list of...     } } 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -