swift3 - How do you write a completion handler in Swift 3? -
i wondering how make completion handler function i'm creating in swift 3. how did function right before updated swift 3:
func logout(completionhandler: (success: bool) -> ()) { backendless.userservice.logout( { ( user : anyobject!) -> () in print("user logged out.") completionhandler(success: true) }, error: { ( fault : fault!) -> () in print("server reported error: \(fault)") completionhandler(success: false) })}
but can't figure out best approach works right now.
in swift 3 function parameter labels in closures gone.
remove occurrences of success:
, add @escaping
func logout(completionhandler:@escaping (bool) -> ()) { backendless?.userservice.logout( { user in print("user logged out.") completionhandler(true) }, error: { fault in print("server reported error: \(fault)") completionhandler(false) }) }
and use it
logout() { success in print(success) }
Comments
Post a Comment