swift - 调用中的无关参数标签“with:”
问题描述
在这段代码中
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 后出现错误
如何修复错误?
解决方案
如无法使用类型为 '(Range<String.Index>)' 的参数列表调用类型为 'Range<String.Index>' 的初始化程序,可以通过删除Range<String.Index>(...)
转换来修复编译器错误。这仍然会导致警告
'characters' 已弃用:请直接使用字符串或子
字符串 substring(with:)' 已弃用:请使用字符串切片下标。
可以用
text = prospectiveText[..<prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)]
但是,您可以更简单地获得相同的结果
text = String(prospectiveText.prefix(maxLength))
推荐阅读
- python - 使用 python-opencv 拍摄的网络摄像头照片很暗
- java - HQL 查询使用有效的 SQL 查询抛出 QueryException
- php - 未捕获的 ArgumentCountError:函数 wc_get_page_id() 的参数太少
- java - Java takeWhile 状态
- r - ggplot:从年份的子集中添加新行
- elasticsearch - 什么相当于 group by 和 collect 作为弹性搜索中的列表?
- sql - ORA-00904: 标识符无效但表名和列名正确?
- angularjs - 在 angularjs 模块/控制器之间传递数据
- java - 使用 Java 构建 Couchbase 缓存应用程序
- selenium - 如何在子选项卡中获取元素的 XPath(Salesforce Lightning 组件)