Swift - Trailing Closure Syntax

前端 未结 1 1414
南笙
南笙 2021-02-05 14:52

I\'m diving into Swift lang by Apple and have some problems using the trailing closure syntax, example:

func test(txt: String, resolve: (name: String) -> Void         


        
相关标签:
1条回答
  • 2021-02-05 15:10

    you have the wrong closure syntax

    test("hello", {(name: String) in 
        println("callback")
    })
    

    or

    test("hello", {
       println("callback: \($0)")
    })
    

    or

    test("hello") {(name: String) in 
        println("callback")
    }
    

    or

    test("hello") {
       println("callback: \($0)")
    }
    
    0 讨论(0)
提交回复
热议问题