【问题标题】:Extraneous argument label 'with:' in call调用中的无关参数标签“with:”
【发布时间】:2018-10-08 16:22:30
【问题描述】:

在这段代码中

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

如何修复错误?

【问题讨论】:

  • 去掉多余的标签?
  • @Paulw11 删除后,我得到Cannot invoke initializer for type 'Range<String.Index>' with an argument list of type '(Range<String.Index>)' 这个错误

标签: swift xcode xcode10


【解决方案1】:

Cannot invoke initializer for type 'Range<String.Index>' with an argument list of type '(Range<String.Index>)' 一样,可以通过删除Range&lt;String.Index&gt;(...) 转换来修复编译器错误。这仍然会导致警告

'characters' 已弃用:请直接使用字符串或子字符串
substring(with:)' 已弃用:请使用字符串切片下标。

可以用

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

但是,您可以使用

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

【讨论】:

    猜你喜欢
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    相关资源
    最近更新 更多