Skip to content

Crash on route index access #108

@emartinson

Description

@emartinson

Sometimes I get crash on

 mutating func dismiss(count: Int = 1) {
    assert(count >= 0)
    var index = endIndex - 1
    var dismissed = 0
    while dismissed < count, index + 1 > rootIndex {
      if self[index].isPresented {
        dismissed += 1
      }
      index -= 1
    }
    goBackTo(index: index)
  }

I suggest to use

self[safe: index]?.isPresented == true instead
extension Collection {
    /// Returns the element at the specified index if it is within bounds, otherwise nil.
    subscript(safe index: Index) -> Element? {
        indices.contains(index) ? self[index] : nil
    }
}

this will eliminate crashes.

Workaround - I do preconditions check on app side for now

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions