In Swift 4, I\'m getting this error when I try to take a Substring
of a String
using subscript syntax.
\'subscript\' is unavaila
- How can I resolve this error?
This error means you can't use an Int in the subscript format – you have to use a String.Index, which you can initialize with an encodedOffset Int.
let myString: String = "foobar"
let lowerBound = String.Index.init(encodedOffset: 1)
let upperBound = String.Index.init(encodedOffset: 3)
let mySubstring: Substring = myString[lowerBound..
- Where is "the documentation comment for discussion" that was referred to in the error?
It's on GitHub in the Swift Standard Library repository in a file called UnavailableStringAPIs.swift.gyb in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying 'Beware of the Leopard'. link