Skip to content

Instantly share code, notes, and snippets.

@alexj70
Created April 22, 2017 19:53
Show Gist options
  • Save alexj70/65e2a47a15efc4eca754d105e7cf4d39 to your computer and use it in GitHub Desktop.
Save alexj70/65e2a47a15efc4eca754d105e7cf4d39 to your computer and use it in GitHub Desktop.
guard case let
enum NetworkResponse {
case response(URLResponse, Data)
case error(Error)
}
func processRequestResponse(_ response: NetworkResponse) {
guard
case let .response(urlResp, data) = response,
let httpResp = urlResp as? HTTPURLResponse,
200..<300 ~= httpResp.statusCode
else {
print("Invalid response, can't process")
return
}
print("Processing \(data.count) bytes…")
/* … */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment