This is my loop
for category in categories! {
NearbyPlaces.getNearbyPlaces(by: category?.name ?? "food", coordinates: currentLocation!, radius: radius, token: self.response?.nextPageToken, completion: didReceiveResponse)
}
where categories
is an array with inside a list of categories of places (google places) (like restaurant, gym, bar) and i use it with a lot of other functions to search nearby places of those categories. My problem is this, now as it is now, it all works properly, so if in my array categories
i have for example 2 elements: bar and gym and near to me there are 10 restaurants and 10 gyms, he will load in my tableView 10 restaurants and 10 gyms. But now that i added a limit to the loadable places i have a problem, if around me there are 10 restaurants and 10 gyms and the limit is (for example) 4, he will not load to me 2 restaurants and 2 gyms but 4 restaurants or 4 gyms, depends on what comes first in the array, so i would like to know how to modify the cycle so that it always uses a different element of the array (so one time use the element in the index 0, after the element in the index 1 etc.)
EDIT
you are right guys, but is not easy to explain clearly my problem, substantially i have two VC with both a tableView, in the first you can chose multiple categories of places (google places) who'll go to fill the array categories, in the second should load x places in x radius (geolocalization) based on the categories chosen in the previous controller, if i don't add a limit of places that can load in my tableview, the loop for does exactly the iterate through the categories one-by-one the PROBLEM is he does not load a place by category at a time but all places of the first item/category, then all places of the second etc. So if i add a limit for example 4 and i have two categories chosen in my array, he will not load 2 places of the first category and two of the second but if near to me (for example) there are 4 or more places of the type of the first category, he will load 4 places of the first type, so this is my problem