14

Currently, I've been using XCode 8 and on the line

let range = key.startIndex...key.startIndex.advancedBy(0)

I get the error:

error: 'advancedBy' is unavailable: To advance an index by n steps call 'index(_:offsetBy:)' on the CharacterView instance that produced the index.

How can I fix this?

A screenshot of the error is below:

advancedBy is unavailable

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Va Visal
  • 884
  • 1
  • 10
  • 17

2 Answers2

23

advancedBy(_:) has been deprecated in Swift v3 and replaced by index(_:offsetBy:). Refer to Apple's migration guide for more info.

The solution to your error:

let range = key.startIndex...key.index(key.startIndex, offsetBy: 0)
Anjan Biswas
  • 7,746
  • 5
  • 47
  • 77
yohannes
  • 1,022
  • 11
  • 13
0

You can achieve what you are after more simply by building a new string rather than manipulating the old one:

let upperCasedFirstCharacter = String(key.characters.first!).uppercased()

let remainder = key.substring(from: key.characters.index(after: key.characters.startIndex))

let selector = "set\(upperCasedFirstCharacter)\(remainder)"
Paulw11
  • 108,386
  • 14
  • 159
  • 186