Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何增加String.CharacterView.Index类型的变量?_Swift_Swift3 - Fatal编程技术网

Swift 如何增加String.CharacterView.Index类型的变量?

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

我(在操场上)试着这样做:

…但我收到以下错误消息:

错误:二进制运算符“+=”不能应用于类型为的操作数 'String.CharacterView.Index'和'Int'

我之所以尝试增加这个索引,是因为我想做如下事情:

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)
}