2016-07-19 187 views
11

Attualmente, Sto usando XCode 8 e sulla linea'advancedBy' non è disponibile in Xcode 8

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

ottengo l'errore:

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

Come posso risolvere questo problema?

Uno screenshot dell'errore è qui sotto:

advancedBy is unavailable

+1

prega di inserire un codice nella questione nonché lo screenshot. – Paulw11

+1

È necessario utilizzare l'offset dell'indice da http://stackoverflow.com/a/38215613/2303865 –

+0

Vedere https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices. md – HAS

risposta

0

si può ottenere che cosa siete dopo più semplicemente con la costruzione di una nuova stringa piuttosto che manipolare il vecchio:

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

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

let selector = "set\(upperCasedFirstCharacter)\(remainder)" 
18

advancedBy(_:) è stato deprecato in Swift v3 e sostituito da index(_:offsetBy:). Fare riferimento a Apple migration guide per ulteriori informazioni.

La soluzione al tuo errore:

let range = key.startIndex...key.index(key.startIndex, offsetBy: 0) 
Problemi correlati