Swift 如何增加String.CharacterView.Index类型的变量?
我(在操场上)试着这样做: …但我收到以下错误消息: 错误:二进制运算符“+=”不能应用于类型为的操作数 'String.CharacterView.Index'和'Int' 我之所以尝试增加这个索引,是因为我想做如下事情:Swift 如何增加String.CharacterView.Index类型的变量?,swift,swift3,Swift,Swift3,我(在操场上)试着这样做: …但我收到以下错误消息: 错误:二进制运算符“+=”不能应用于类型为的操作数 'String.CharacterView.Index'和'Int' 我之所以尝试增加这个索引,是因为我想做如下事情: input[position] …并在输入中访问特定字符 在这一点上,我已经知道我不能在位置上使用这个二进制运算符。什么是可行的解决方案 我正在使用Swift 3和Xcode版本8.0 beta 6(8S201h)在Swift 3中,“集合移动其索引”,比较 关于快速进化
input[position]
…并在输入中访问特定字符
在这一点上,我已经知道我不能在位置上使用这个二进制运算符。什么是可行的解决方案
我正在使用Swift 3和Xcode版本8.0 beta 6(8S201h)在Swift 3中,“集合移动其索引”,比较
关于快速进化
就你而言
private func advance() {
input.formIndex(&position, offsetBy: 1)
}
将使指数位置前进一步。在这里你必须确保
如果索引不等于endIndex
,也可以使用
private func advance() {
input.formIndex(&position, offsetBy: 1, limitedBy: input.endIndex)
}
private func advance() {
input.formIndex(&position, offsetBy: 1, limitedBy: input.endIndex)
}