The code below will help you in declaration of completion handler  and how to call the completion handler in swift.
To declare a completion handler in swift use the line   :
 typealias completionHander = (sucess: Bool)->Void 
//decalration of completion handler
  typealias completionHander = (sucess: Bool)->Void 
// definition of method with completion handler
    func mycallingFucntion(senderValue: Int, mycompletion:completionHander)->Void 
    {
        print("value in function \(senderValue)")
        if senderValue > 10
        {
        mycompletion(sucess: false);
        }
        else
        {
            mycompletion(sucess: true)
        }
    }
//calling of completion handler
mycallingFucntion(100) { (sucess) -> Void in
            print("\(sucess)")
}
                       
                    
0 Comment(s)