Listing 20.14, ++ is deprecated


Am wondering what is the recommended replacement for this line in method Parser.getNextToken:

return tokens[position++]

I have tried introducing a new local variable:

        return tokens[nextToken]```

And the following:

```position += 1
        return tokens[position]```

Both give a runtime error:

```Invalid token during parsing: Plus```

The way tokens[position++] worked was to take the current value of position, get that token, and then increment position afterwards. Therefore, the equivalent code without ++ would be:

let token = tokens[position]
position += 1
return token

Oh, so I was returning the wrong token. Got it! Thanks


In Swift 3.0 String.CharacterView.Index works a lot different and even position += 1 doesn’t compile, does anyone know the solution for this?


in case anyone else gets stuck here something like

return tokens[tokens.index(after: position)]

appears to work