I am making an API call for muscles relating to an exercise, the call looks like this:
func loadPrimaryMuscleGroups(primaryMuscleIDs: [Int]) {
print(primaryMuscleIDs)
let url = "https://wger.de/api/v2/muscle"
Alamofire.request(url).responseJSON { response in
let jsonData = JSON(response.result.value!)
if let resData = jsonData["results"].arrayObject {
let resData1 = resData as! [[String:AnyObject]]
if resData1.count == 0 {
print("no primary muscle groups")
self.musclesLabel.isHidden = true
} else {
print("primary muscles used for this exercise are")
print(resData)
self.getMuscleData(muscleUrl: resData1[0]["name"] as! String)
}
}
}
}
This returns me a whole list of all the muscles available, I need it to just return the muscles the exercise requires. This is presented in exercises as an array of muscle id's, which I feed in via the viewDidLoad below
self.loadPrimaryMuscleGroups(primaryMuscleIDs: (exercise?.muscles)!)
So I am feeding the exercises muscle array into the func as an [Int] but at this point im stumped on how to filter the request so that the resulting muscle data are only the ones needed for the exercise.
I was thinking it would be something like using primaryMuscleIDs to filter the id property of a muscle in the jsonData response, but im not sure how to go about that?
Thanks for any clarify here, hopefully I have explained it clearly enough to come across well