2017-11-08 6 views
0

私はSwift 4に更新されていないMapBoxナビゲーションフレームワークを使用しています。ここにコードがあります。私は本当に助けに感謝します。ありがとうございました。Swift 4: 'subscript'が利用できないエラー

private func extractNextChunk(_ encodedString: inout String.UnicodeScalarView) throws -> String { 
    var currentIndex = encodedString.startIndex 

    while currentIndex != encodedString.endIndex { 
     let currentCharacterValue = Int32(encodedString[currentIndex].value) 
     if isSeparator(currentCharacterValue) { 
      let extractedScalars = encodedString[encodedString.startIndex...currentIndex] 
      encodedString = encodedString[encodedString.index(after: currentIndex)..<encodedString.endIndex] 

      return String(extractedScalars) 
     } 

     currentIndex = encodedString.index(after: currentIndex) 
    } 

    throw PolylineError.chunkExtractingError 
} 

enter image description here

答えて

4

エラーメッセージは誤解を招きます。実際の問題は、 String.UnicodeScalarViewの範囲を添字としてString.UnicodeScalarView.SubSequenceを返すため、 encodedStringに割り当てることができないことです。また

encodedString = String.UnicodeScalarView(encodedString[encodedString.index(after: currentIndex)...]) 

(そしておそらく単純)の周りに他の方法で行くと はなくencodedStringの最初の部分を削除します:

encodedString.removeSubrange(...currentIndex) 

一つの解決策は、サブシーケンスからString.UnicodeScalarView を作成することです

どちらの場合でも、「片側範囲」を使用することができます。 SE-0172

+0

ありがとうございます。私はそのテストを与えるでしょう。上に貼り付けた実際のコードに追加してください。それは私があなたの答えを100%確信しているわけではないので、大きな助けになるでしょう。 –

+1

@ChelsMcKay:コンパイラエラーの原因となった 'encodedString = ...'行を置き換えるだけです。 –

関連する問題