-4
let subString = self[Range(start: start++, end: endIndex)]
if subString.hasPrefix(other){
    return true
}

i have this code in swift 2.3, i used this code as an extension for string value, xcode converted it as follow

let subString = self[((start++) ..< endIndex)]

and start giving me error

Unary operator '++' cannot be applied to an operand of type '@lvalue String.Index' (aka '@lvalue String.CharacterView.Index')

i don't know now how exactly Xcode want me to write it?

Hamish
  • 78,605
  • 19
  • 187
  • 280
Gurjot Kalsi
  • 33
  • 11
  • Compare [How does String.Index work in Swift 3](http://stackoverflow.com/q/39676939/2976878) – you want to do `index(after: start)` (this won't mutate `start`, but you can easily do that by assigning to it on a seperate line). – Hamish Apr 13 '17 at 10:38
  • @Harmish that helped (y) – Gurjot Kalsi Apr 13 '17 at 10:41
  • that is what i am doing! i am just saying if i have talk about the same question and i can't comment! then what to do? – Gurjot Kalsi Apr 13 '17 at 11:12

1 Answers1

2

In Swift 3 you cannot increment String.Index directly by an Int.

I don't know exactly how start is defined but you could replace start++ with

self.index(start, offsetBy: 1)
vadian
  • 274,689
  • 30
  • 353
  • 361