Advertisement
Don_Mag

Untitled

Mar 13th, 2020
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.10 KB | None | 0 0
  1.     func fetchData(_ category: String) {
  2.         indicator.setupIndicatorView(view, containerColor: .customDarkGray(), indicatorColor: .white)
  3.         let urlString = "https://api.spoonacular.com/recipes/random?number=5&apiKey=REPLACE-WITH-YOUR-API-KEY&tags=\(category)"
  4.         print("urlString:", urlString)
  5.         print()
  6.         AF.request(urlString).responseJSON { (response) in
  7.             if let error = response.error {
  8.                 print(error)
  9.             }
  10.             do {
  11.                 if let data = response.data {
  12.                     print("received response data")
  13.                     print()
  14.                     self.recipes = try JSONDecoder().decode(Recipes.self, from: data)
  15.                     print("self.recipes:", self.recipes)
  16.                     print()
  17.                     self.recipesDetails = self.recipes?.recipes ?? []
  18.                     print("self.recipesDetails count:", self.recipesDetails.count)
  19.                     print()
  20.                     print("self.recipesDetails:", self.recipesDetails)
  21.                     print()
  22.                     DispatchQueue.main.async {
  23.                         print("calling self.mainView.foodTableView.reloadData()")
  24.                         print()
  25.                         self.mainView.foodTableView.reloadData()
  26.                     }
  27.                 }
  28.                
  29.             } catch {
  30.                 print(error)
  31.             }
  32.             self.indicator.hideIndicatorView(self.view)
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement