How to set a function as function argument in Swift 3

前端 未结 3 367
轮回少年
轮回少年 2021-01-21 02:22

Q: Is it possible to pass a function as function argument in Swift 3?

To refactor my code, I want to have a global function. At the end of this function

3条回答
  •  天涯浪人
    2021-01-21 03:02

    Functions are first class in swift so you can pass them like so:

    func getButton(_ myFunc: () -> Void, _ title: String) {
    

    You need to specify the signature of the function in the type, i.e. parameter types and return type

提交回复
热议问题