Callback function syntax in Swift

后端 未结 5 937
南旧
南旧 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:39

    try below code updated for Swift 3

    func getBoolValue(number : Int, completion: (Bool)->()) {
        if number > 5 {
            completion(true)
        } else {
            completion(false)
        }
    }
    
    getBoolValue(number : 8, completion:{ result in
        print(result)
    })
    

提交回复
热议问题