Don_Mag icon

Untitled

Don_Mag | PRO | 03/13/20 04:04:42 PM UTC | 0 ⭐ | 1557 👁️ | Never ⏰ | []
Swift |

1.1 KB

|

None

|

0 👍

/

0 👎

    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)
        }
    }

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎