2016-09-20 1 views
2

上のエラーここで前のXcode-8スウィフトコールだSwift3への自動アップグレードを使用して...「コレクション対応...」スウィフト3アップグレード

func gappizeAtDoubleNewlines() 
    { 
    let t = self.text! 
    var index = t.startIndex 
    var follow = index.advancedBy(1) 

    for i in 0 ..< (t.characters.count-4) 
     { 
     let r = index ... follow 
     if (t.substringWithRange(r) == "\n\n") 
      { alterLineGapHere(i) } 

     index = index.advancedBy(1) 
     follow = index.advancedBy(1) 
     } 
    } 

が、私は

...これらのエラーを得ましたテキストで

enter image description here

、Swift3内の溶液は何

func gappizeAtDoubleNewlines() 
    { 
    let t = self.text! 
    var index = t.startIndex 
    var follow = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1) 

    for i in 0 ..< (t.characters.count-4) 
     { 
     let r = index ... follow 
     if (t.substring(with: r) == "\n\n") 
      { alterLineGapHere(i) } 

     index = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1) 
     follow = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1) 
     } 
    } 

+0

@ハミッシュ - ありがとうございました。 – Fattie

+0

確かなこと - 私は誤ってコメントに質問に答える習慣を持っています:) – Hamish

答えて

3

SE-0065: 'Collections move their indices'を参照してください - この場合にはあなただけのtとエディタのプレースホルダを置き換えることができます。

func gappizeAtDoubleNewlines() { 

    let t = self.text! 
    var index = t.startIndex 

    // Note that because substring(by:) takes a Range<String.Index>, rather than 
    // a ClosedRange, we have to offset the upper bound by one more. 
    var follow = t.index(index, offsetBy: 2) 

    for i in 0 ..< (t.characters.count-4) { 
     let r = index ..< follow 
     if (t.substring(with: r) == "\n\n") { 
      alterLineGapHere(i) 
     } 

     index = t.index(index, offsetBy: 1) 
     follow = t.index(follow, offsetBy: 1) 
    } 
} 

ノートもののStringCollectionそのものではない、それだけで前方t.charactersへのインデックス付けのためのいくつかの便利なメソッドを実装していることであり、Collectionである。

+0

と非常に最新のスウィフトでグーグルグーグルが、私はこの拡張機能を便利に見つけました... http://stackoverflow.com/a/39677704/294884 – Fattie