Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func fetchData(_ category: String) {
- indicator.setupIndicatorView(view, containerColor: .customDarkGray(), indicatorColor: .white)
- let urlString = "https://api.spoonacular.com/recipes/random?number=5&apiKey=REPLACE-WITH-YOUR-API-KEY&tags=\(category)"
- print("urlString:", urlString)
- print()
- AF.request(urlString).responseJSON { (response) in
- if let error = response.error {
- print(error)
- }
- do {
- if let data = response.data {
- print("received response data")
- print()
- self.recipes = try JSONDecoder().decode(Recipes.self, from: data)
- print("self.recipes:", self.recipes)
- print()
- self.recipesDetails = self.recipes?.recipes ?? []
- print("self.recipesDetails count:", self.recipesDetails.count)
- print()
- print("self.recipesDetails:", self.recipesDetails)
- print()
- DispatchQueue.main.async {
- print("calling self.mainView.foodTableView.reloadData()")
- print()
- self.mainView.foodTableView.reloadData()
- }
- }
- } catch {
- print(error)
- }
- self.indicator.hideIndicatorView(self.view)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement