I'm having trouble converting my Swift 3 code to Swift 4. I've managed to translate everything else in the app successfully, but am having trouble with a single line of code:
cleanURL = cleanURL.substring(to: cleanURL.index(before: cleanURL.endIndex))
The error I'm getting is this:
ViewController.swift:62:33: 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
Well, do what the error says,use String slicing subscript with a 'partial range upto' operator:
let actuallyCleanURL = kindaCleanURL[..<kindaCleanURL.endIndex]
Note that this returns a Substring
. If you need to do more slicing operations, do them on this substring. Once you're done, promote your to a String
by running it through the String
initializer (String(mySubString)
), causing a copy of the memory to be made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With