Created
May 18, 2017 09:41
-
-
Save boska/02204f35f7f16357d2a195a647e8350d to your computer and use it in GitHub Desktop.
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
extension URL { | |
func fetch(completionHandler: ((Data) -> ())? = nil) { | |
print("Request: \(self)") | |
URLSession.shared.dataTask(with: self) { | |
guard | |
let response = $1 as? HTTPURLResponse, response.statusCode == 200, | |
let data = $0, $2 == nil | |
else { return } | |
completionHandler?(data) | |
}.resume() | |
} | |
} | |
let url = URL() | |
url.fetch { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment