In Swift 4, I\'m getting this error when I try to take a Substring
of a String
using subscript syntax.
\'subscript\' is unavaila
Your question (and self-answer) has 2 problems:
Subscripting a string with Int
has never been available in Swift's Standard Library. This code has been invalid for as long as Swift exists:
let mySubstring: Substring = myString[1..<3]
The new String.Index(encodedOffset: )
returns an index in UTF-16 (16-bit) encoding. Swift's string uses Extended Grapheme Cluster, which can take between 8 and 64 bits to store a character. Emojis make for very good demonstration:
let myString = "