# The wrong default \`Indices\` type is being used

**URL:** <https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598>\
**Category:** Using Swift\
**Tags:** collection\
**Created:** [March 18, 2025, 5:48am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598 "2025-03-18T05:48:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 18, 2025, 5:48am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598/1 "2025-03-18T05:48:48Z")

</div>

I thought if you define a `Collection` type, but don't explicitly provide a `Indices` type, the default will be `DefaultIndices`. Instead, I got `Range<Int>`, which is bad since it uses a spacing of 1, which my type doesn't use. Did some assumption change (that I didn't see browsing the source code)? Or is there some switch between `DefaultIndices` and `Range`, and I don't know how to override it?

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [March 18, 2025, 5:56am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598/2 "2025-03-18T05:56:45Z")

</div>

[Is your type a `RandomAccessCollection`?](https://github.com/swiftlang/swift/blob/b904e96199e06fb77ecd9c758b5937997db25b9c/stdlib/public/core/RandomAccessCollection.swift#L269-L274)

---

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 18, 2025, 6:00am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598/3 "2025-03-18T06:00:46Z")

</div>

Just added the `RAC` conformance. Before, it was just a `BidirectionalCollection`.

---

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 18, 2025, 6:10am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598/4 "2025-03-18T06:10:28Z")

</div>

I just re-read the parts of "RandomAccessCollection.swift" that I usually ignore. I see the `Range` override.

I'm not sure if it's changed, but the types associated with the `stride` top-level functions could work, except they skip `Collection` support.

---

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 19, 2025, 5:35am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598/5 "2025-03-19T05:35:51Z")

</div>

I had to make a custom `Indices` type. At least I moved the main index-iteration logic to that type, which the collection type indirectly uses.
