Created
October 25, 2017 11:20
-
-
Save azamsharp/c98b9663005090e7d94a5ddad0d0153c 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
extension ArticleListViewModel { | |
func get(completion :@escaping (ArticleListViewModel) -> ()) { | |
// Use a URL builder scheme here instead of just using the string URL | |
let url = URL(string :"https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=0cf790498275413a9247f8b94b3843fd")! | |
// Instead of getArticles method webservice should be generic and return the requested | |
// object/objects of requested type | |
self.webservice.getArticles(url: url) { articles in | |
self.articles = articles.flatMap { article in | |
ArticleViewModel(article: article) | |
} | |
DispatchQueue.main.async { | |
completion(self) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment