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,

  1. substring(to:)
  2. 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 solving the code deprecation error.

I used them as follows,

// returns the “/one”
// returns the “/four”

Software Engineer | . Computer Science from Technische Universitaet Berlin

Software Engineer | M.Sc. Computer Science from Technische Universitaet Berlin