首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“收集相应的.”Swift 3升级错误

“收集相应的.”Swift 3升级错误
EN

Stack Overflow用户
提问于 2016-09-20 06:38:49
回答 1查看 1.3K关注 0票数 2

这是一个预Xcode-8快速电话..。

代码语言:javascript
复制
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)
        }
    }

通过自动升级到Swift3,我得到了这些错误.

在文本中,

代码语言:javascript
复制
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)
        }
    }

Swift3中的解决方案是什么??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-03 15:38:11

参见SE-0065:“集合移动其索引” -在本例中,您只需将编辑器占位符替换为t

代码语言:javascript
复制
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)
    }
}

尽管注意到String本身并不是Collection,但它只是实现了一些方便的方法来为转发到t.characters (即Collection )的索引进行索引。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39587274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档