How to get rid of $0 in Swift closure? -
let's have class:
class test { func somemethod() {} init(closure:(test)->void) { closure(self) } } i can call init in method of class (1)
test { $0.somemethod() } or (2)
test { t in t.somemethod() } is there possible solution allow write exact same thing without "$0" or "t"? code (3)
test { somemethod() } behaviour must in (1) or (2).
is possible? maybe not closures, other swift feature?
i want kotlin type-safe builder: http://kotlinlang.org/docs/reference/type-safe-builders.html
not sure you're after, wonder whether little bit of voodoo might useful you:
class test { var name : string init(_ name:string) {self.name = name} func somemethod() { println("hi, name \(name)") } } let f = test.somemethod let t1 = test("matt") let t2 = test("bealex") f(t1)() // hi, name matt f(t2)() // hi, name bealex point f(t1) function which, when called, sends somemethod instance t1. might able mileage out of that.
Comments
Post a Comment