Created
February 4, 2019 18:47
-
-
Save azamsharp/2335781d35bc8d52f0a9bd119ddb44ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func getArticles(with url: URL, completion: @escaping ([Article]?) -> ()) { | |
URLSession.shared.dataTask(with: url) { data, response, error in | |
if let error = error { | |
print(error.localizedDescription) | |
completion(nil) | |
} else if let data = data { | |
let articlesList = try? JSONDecoder().decode(ArticleList.self, from: data) | |
completion(articlesList?.articles) | |
} | |
}.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment