Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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
Ios Swift 4:';子串(to:)&x27;不赞成_Ios_Swift_Swift4 - Fatal编程技术网

Ios Swift 4:';子串(to:)&x27;不赞成

Ios Swift 4:';子串(to:)&x27;不赞成,ios,swift,swift4,Ios,Swift,Swift4,我无法将Swift 3代码转换为Swift 4。我成功地翻译了应用程序中的所有其他内容,但我在一行代码中遇到了问题: cleanURL = cleanURL.substring(to: cleanURL.index(before: cleanURL.endIndex)) 我得到的错误是: ViewController.swift:62:33: 'substring(to:)' is deprecated: Please use String slicing subscript with a '

我无法将Swift 3代码转换为Swift 4。我成功地翻译了应用程序中的所有其他内容,但我在一行代码中遇到了问题:

cleanURL = cleanURL.substring(to: cleanURL.index(before: cleanURL.endIndex))
我得到的错误是:

ViewController.swift:62:33: 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.

那么,按照错误所说的做,使用带有“部分范围到”运算符的字符串切片下标:

let actuallyCleanURL = kindaCleanURL[..<kindaCleanURL.endIndex]

让actuallyCleanURL=kindaCleanURL[…你确定变异一个变量而不是定义一个新变量是有意义的吗?如果去掉最后一个符号后url是“干净”的,为什么它被称为“干净url”甚至在此之前?检查。似乎是重复的。这不是返回字符串,而是返回字符串。子序列。您需要将其转换为带有字符串(…)的字符串,因为它可以像预期的那样工作。@timgcarlson很好