Created
January 28, 2019 11:31
-
-
Save salmaanahmed/9114b6acdba148c85515c946b8b46704 to your computer and use it in GitHub Desktop.
This API expresses exactly the intended result (either an error or data and response, never all or none) and allows them to be handled much more clearly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URLSession.shared.dataTask(with: url) { (result: Result<(response: URLResponse, data: Data), Error>) in // Type added for illustration purposes. | |
switch result { | |
case let .success(success): | |
handleResponse(success.response, data: success.data) | |
case let .error(error): | |
handleError(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment