String slicing substring — Mastering Swift 4 — Fourth Edition
Code deprecation error in playground when I was trying the example mentioned in the page 79 of the book “Mastering Swift 4 — Fourth Edition”.
The code snippet:
path.substring(to: startIndex)
// returns the “/one”path.substring(from: endIndex)
// returns the “/four”
The following are deprecated in Swift 4,
substring(to:)
substring(from:)
you get error in playground to change the code and use String
slicing subscript with a 'partial range from' operator.
I found the solution for this question on stackoverflow https://stackoverflow.com/questions/45562662/how-can-i-use-string-slicing-subscripts-in-swift-4 solving the code deprecation error.
I used them as follows,
path[…startIndex]
// returns the “/one”path[endIndex…]
// returns the “/four”
If you like my articles please follow me. You can also support me by https://www.buymeacoffee.com/akarshseggemu