[ad_1]
I’m rookie in programming and I’m attempting to resolve this concern. It got here up when i combine a collectionView in tableView, then I want to present information from apiRest web site to that cell, why it’s not displaying up?
Api: https://spoonacular.com/food-api/docs#Authentication
I’ve already carried out my apiKey and all the things it must go.
Right here is my apiService code:
Thanks a lot prematurely.
import Basis
import Alamofire
class APIService: NSObject {
static let sharedInstance = APIService()
let baseUrl = "https://api.spoonacular.com/recipes/"
let headers = ["Content-Type": "application/json",
"Accept":"application/json",
"apiKey":"<api-key>"]
func getRecipe(completion: @escaping (_ output: SearchRecipeModel?, _ hasError: String?) -> ()) {
let url = baseUrl+"(Providers.complexSearch)"
Spinner.begin()
Alamofire.request(url, methodology: .get, encoding: JSONEncoding.default, headers: headers)
.responseJSON { dataResponse in
change(dataResponse.outcome){
case .success:
Spinner.cease()
print("success: ",dataResponse)
do {
let decodedObject = attempt JSONDecoder().decode(SearchRecipeModel.self, from: dataResponse.knowledge!)
print(decodedObject)
completion(decodedObject, nil)
} catch let error as NSError {
print(error)
completion(nil, "Error Comes")
}
break
case .failure:
Spinner.cease()
print("failure")
completion(nil, "Service Failed")
break
}
}
}
}
[ad_2]
