Is it possible to use multiple trailing closures in swift? -
i know possible define methods accept closures this:
a. single closure input parameter
func testofclosures (flag: int, closure1: () -> ()) { closure1() }
b. multiple closures input parameters
func testofclosures (flag: int, closure1: () -> (), closure2: () -> (), closure3: () -> ()) { switch flag { case 1: closure1() case 2: closure2() default: closure3() } }
interestingly in first case can invoke this:
testofclosures(1){ println("print closure 1") }
but in second case, cannot invoke this:
testofclosures(1,{ println("print closure 1") }, { println("print closure 2") }) { println("print closure 3") }
and have invoke this:
testofclosures(1,{ println("print closure 1") }, { println("print closure 2") }, { println("print closure 3") })
any reasons?
it looks trailing closure syntax specific position of opening {
, requires on same line closing )
the below works
testofclosures(1,{ println("print closure 1") }, { println("print closure 2") }) { println("print closure 3") }
as far multiple trailing closures, not possible. documentation states final closure using special syntax.
Comments
Post a Comment