调用中的无关参数标签 'with:'

Extraneous argument label 'with:' in call

在此代码中

text = prospectiveText.substring( with: Range<String.Index>(prospectiveText.startIndex ..< prospectiveText.characters.index(prospectiveText.startIndex, offsetBy: maxLength)) )

我将 xcode 更新为 10.01

后出现错误 Extraneous argument label 'with:' in call

如何修复该错误?

一样,可以通过删除 Range<String.Index>(...) 转换来修复编译器错误。这仍然会导致警告

'characters' is deprecated: Please use String or Substring directly
substring(with:)' is deprecated: Please use String slicing subscript.

可以用

修复
text = prospectiveText[..<prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)]

但是,您可以使用

更简单地实现相同的结果
text = String(prospectiveText.prefix(maxLength))