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
Post a Comment