这是一个预Xcode-8快速电话..。
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,我得到了这些错误.

在文本中,
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中的解决方案是什么??
发布于 2016-10-03 15:38:11
参见SE-0065:“集合移动其索引” -在本例中,您只需将编辑器占位符替换为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)
}
}尽管注意到String本身并不是Collection,但它只是实现了一些方便的方法来为转发到t.characters (即Collection )的索引进行索引。
https://stackoverflow.com/questions/39587274
复制相似问题