Created
October 22, 2017 02:53
-
-
Save azamsharp/03cc6d17b7176ac6a838c5fb2a52b423 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 loadArticles(callback :([Article] -> ())) { | |
URLSession.shared.dataTask(with: url) { data, response, error in | |
if let data = data { | |
let json = try! JSONSerialization.jsonObject(with: data, options: []) | |
let dictionary = json as! JSONDictionary | |
let articleDictionaries = dictionary["articles"] as! [JSONDictionary] | |
articles = articleDictionaries.flatMap { dictionary in | |
return Article(dictionary :dictionary) | |
} | |
} | |
DispatchQueue.main.async { | |
callback(articles) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment