ios - 更新子字符串(到 :) results in generic parameter could not be inferred

标签 ios swift swift4

我正在使用一个使用 substring(to:) 的框架,它现在已在 swift 4 中弃用。

let split = stripped.substring(to: stripped.range(of: ";")?.lowerBound ?? stripped.endIndex)

我将其更新为以下代码,但现在出现“无法推断通用参数”错误,并且“..”带有下划线。

let split = stripped[..<stripped.range(of: ";")?.lowerBound ?? stripped.endIndex]

不确定我应该如何解决这个问题。

最佳答案

让我们让这段代码更清晰一点:

let range = stripped.range(of: ";")?.lowerBound ?? stripped.endIndex
let split = String(stripped[..<range])

但是你好像想获取某个字符之前的子串。我有另一种方法可以做到这一点:

let split: String = stripped.components(separatedBy: ";").first!

关于ios - 更新子字符串(到 :) results in generic parameter could not be inferred,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47149025/

相关文章:

ios - calendarsForEntityType :EKEntityTypeReminder is empty first time, 随后工作

ios - 使用移动触摸旋转 Sprite 节点

swift - 无法对不可变值 : 'self' is immutable 使用变异成员

json - 如何通过 Swift 4 的 Decodable 协议(protocol)使用自定义 key ?

ios - ViewController 始终加载相同的链接

ios - Interface Builder 中的 "User Defined Runtime Attributes"是什么?

ios - 如何找到 NSMutableArray 的最小和最大对象

ios - 如何在 Storyboard 创建的标签栏 Controller 上编写代码?

ios - 处理 "mobilephone"URL 方案在真实设备上不起作用

swift 。让 NSTimer 在应用程序关闭后继续运行