Callback function syntax in Swift

后端 未结 5 954
南旧
南旧 2020-12-08 10:12

I am attempting pass a function to another function and then have the passed function executed passing to it a variable.

Here is my code:

func showSt         


        
5条回答
  •  余生分开走
    2020-12-08 10:51

    I use this way :

    ViewController1

    destination.callback = { (id) -> Void in
                print("callback")
                print(id)
            }
    

    ViewController2

    var callback: ((_ id: Int) -> Void)?
    callback?(example_id)
    

提交回复
热议问题