Is it possible to convert String.Index to its underlying index number?

I am aware Swift deliberately hides details (the actual index number) for safety, by introducing this verbose construct.

But I just got curious - is it possible to convert Index back to its underlying number?

Answered by Claude31 in 773182022

You're right, it is really verbose and a real pain to use.

So some extensions are welcome: https://stackoverflow.com/questions/34540185/how-to-convert-index-to-type-int-in-swift

Accepted Answer

You're right, it is really verbose and a real pain to use.

So some extensions are welcome: https://stackoverflow.com/questions/34540185/how-to-convert-index-to-type-int-in-swift

Is it possible to convert String.Index to its underlying index number?
 
 
Q