2016-07-19 12 views
11

Obecnie Używam XCode 8 i na linii'advancedBy' jest niedostępny w Xcode 8

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

pojawia się błąd:

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

Jak mogę rozwiązać ten problem?

zrzut ekranu z błędem jest poniżej:

advancedBy is unavailable

+1

Proszę podać swój kod w pytaniu, a także zrzut ekranu. – Paulw11

+1

Należy użyć index offsetBy http://stackoverflow.com/a/38215613/2303865 –

+0

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

Odpowiedz

0

Można osiągnąć to, czego po prościej budując nowy ciąg zamiast manipulowania starą:

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(_:) został przestarzały w wersji Swift v3 i zastąpiony przez index(_:offsetBy:). Więcej informacji można znaleźć w Apple's migration guide.

Rozwiązanie do błędu:

let range = key.startIndex...key.index(key.startIndex, offsetBy: 0) 
Powiązane problemy