I'm not very familiar with error handling and so any advice would be really appreciated.
My code makes multiple calls recursively to the Apple API for calculating a route as it needs to calculate the distance for multiple options.
do {
directions.calculate(completionHandler: {(response, error) in
let response = (response?.routes)! //This line bugs out
for route in response {
//code
completion(result, error)
}
})
}
catch {
print(error.localizedDescription)
}
It tends to crash on the 5th or 6th time, and I wondered if there was a way to stop the application crashing and notify instead.
Thanks