“Functions are a first-class type” in swift?

后端 未结 5 1292
北海茫月
北海茫月 2021-02-03 13:21

the little knowledge , I have about first class function is that it supports passing functions as arguments and we can also return them as the values in another function ... I a

5条回答
  •  野的像风
    2021-02-03 14:26

    A very simple example to demonstrate this behaviour:

    func functionA() {
        println("Hello by functionA")
    }
    
    func executeFunction(function: () -> ()) {
        function()
    }
    
    executeFunction(functionA)
    

提交回复
热议问题