Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.82 KB | None | 0 0
  1.    private func loadArticles() {
  2.        
  3.         // this url should be part of the URL builder scheme and not right inside the
  4.         // view controller but right now we are focused on MVVM
  5.         let url = URL(string: "https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=0cf790498275413a9247f8b94b3843fd")!
  6.        
  7.         // this web service should use generic types. Again this is not part of the implementation
  8.         // as we are focusing on MVVM model
  9.         Webservice().getArticles(url: url) { articles in
  10.             print(articles)
  11.            
  12.             let articles = articles.map { article in
  13.                 return ArticleViewModel(article :article)
  14.             }
  15.            
  16.             self.viewModel = ArticleListViewModel(articles :articles)
  17.            
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement