Skip to content

Commit 69350fd

Browse files
committed
Use precondition to provide more detail in future possible crash report.
1 parent 2929bfb commit 69350fd

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Sources/MapboxCoreNavigation/RouteController.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,14 @@ open class RouteController: NSObject {
312312
let newStepIndex = Int(status.stepIndex)
313313
let newIntersectionIndex = Int(status.intersectionIndex)
314314

315+
let oldLegIndex = progress.legIndex
315316
if newLegIndex != progress.legIndex {
316317
progress.legIndex = newLegIndex
317318
}
319+
320+
if newStepIndex != progress.currentLegProgress.stepIndex {
321+
precondition(progress.currentLegProgress.leg.steps.indices.contains(newStepIndex), "The stepIndex: \(newStepIndex) is higher than steps count: \(progress.currentLegProgress.leg.steps.count) of the leg :\(newLegIndex) or not included. The old leg index: \(oldLegIndex) will not be updated in this case.")
318322

319-
if (newStepIndex != progress.currentLegProgress.stepIndex) && (newStepIndex < progress.currentLeg.steps.endIndex) {
320323
progress.currentLegProgress.stepIndex = newStepIndex
321324
}
322325

Sources/MapboxCoreNavigation/RouteLegProgress.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open class RouteLegProgress: Codable {
1616
*/
1717
public var stepIndex: Int {
1818
didSet {
19-
assert(stepIndex >= 0 && stepIndex < leg.steps.endIndex)
19+
precondition(leg.steps.indices.contains(stepIndex), "It's not possible to set the stepIndex: \(stepIndex) when it's higher than steps count \(leg.steps.count) or not included.")
2020
currentStepProgress = RouteStepProgress(step: currentStep)
2121
}
2222
}
@@ -141,11 +141,11 @@ open class RouteLegProgress: Codable {
141141
- parameter stepIndex: Current step the user is on.
142142
*/
143143
public init(leg: RouteLeg, stepIndex: Int = 0, spokenInstructionIndex: Int = 0) {
144+
precondition(leg.steps.indices.contains(stepIndex), "It's not possible to set the stepIndex: \(stepIndex) when it's higher than steps count \(leg.steps.count) or not included.")
145+
144146
self.leg = leg
145147
self.stepIndex = stepIndex
146148

147-
precondition(leg.steps.indices.contains(stepIndex), "It's not possible to create RouteLegProgress without any steps or when stepIndex is higher than steps count.")
148-
149149
currentStepProgress = RouteStepProgress(step: leg.steps[stepIndex], spokenInstructionIndex: spokenInstructionIndex)
150150
}
151151

0 commit comments

Comments
 (0)