How do you write a completion handler in Swift 3?

In Swift 3 the function parameter labels in closures are gone.

Remove all occurrences of success: and add @escaping

func Logout(completionHandler:@escaping (Bool) -> ()) {
    backendless?.userService.logout(
        { user in
            print("User logged out.")
            completionHandler(true)
        },
        error: { fault in
            print("Server reported an error: \(fault)")
            completionHandler(false)
    })
}

And use it

Logout() { success in
   print(success)
}

Leave a Comment

tech