gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:37:21 25 4
gpt4 key购买 nike

在这段代码中

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

我收到错误 Extraneous argument label 'with:' in call在我将 xcode 更新到 10.01 之后

如何修复错误?

最佳答案

Cannot invoke initializer for type 'Range<String.Index>' with an argument list of type '(Range<String.Index>)' ,可以通过删除 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))

关于swift - 调用中的无关参数标签 'with:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com