Data.popFirst(), removeFirst() adjust indices

A fundamental requirement of the Collection protocol is that slices share indices with the parent collection. It is incredibly useful, because it means that for any valid index, slice[index] == collection[index], and many generic collection algorithms are much more efficient because of it.

When you want to reset the indices for some reason, just create a fresh Data instance from the Data.SubSequence:

let slice = myData.dropFrist(20)
let reset = Data(slice)
assert(reset.startIndex == 0) // ✓

But it is usually much better to just write your code in terms of a generic Collection as much as possible. That way the compiler prevents you from making mistakes and by definition also steers your design in a more performant direction. For example, write extension Collection or extension Collection where Element == UInt8 instead of extension Data. A bonus is that you get the same methods for free on Data, Data.SubSequence, [UInt8], [UInt8].SubSequence and even String.UTF8View and String.UTF8View.SubSequence.