Itβs not so difficult actually. called Swift closures).
public func someFunction(success: (response: AnyObject!) -> Void, failure: (error: NSError?) -> Void) { }
And that's what you call it.
someFunction(success: { (response) -> Void in // Handle success response }) { (error?) -> Void in // Do error handling stuff }
In your case, I get this block, processing the server response. Most likely, login. The success block will be called if the network operation completes successfully. In it, you save the received access token from your server.
The failure block is called if the network request fails. You might want to display an error message, display a warning that there is a user in it.
If you are confused by the syntax, I suggest referring to these two sites. For Objective-C block syntax and for Swift close syntax .
Isuru
source share