Tracks
/
Swift
Swift
/
Syllabus
/
Opaque Indices
Op

Opaque Indices in Swift

0 exercises

About Opaque Indices

Instead of directly indexing into string, one must instead compute a value of type String.Index and supply that index instead. Note that these indices are not meant to be human-consumable on their own. They are what is referred to as opaque indices ,as humans need not know what is inside them.

let csv = "apple,pear,peach,orange,cherry,lime,goosberry"
let index = csv.index(csv.startIndex, offsetBy: 21)
csv[index]
// => "g"
print(index)
// => Index(_rawBits: 1376513)
Edit via GitHub The link opens in a new window or tab