【问题标题】:substring(from:)' is deprecated. Use string slicing subscript with a 'partial range from' operatorsubstring(from:)' 已弃用。使用带有“部分范围”运算符的字符串切片下标
【发布时间】:2019-03-13 14:00:07
【问题描述】:

我刚刚在 Xcode 10.1 上将一个应用从 swift3 转换为 swift4.2

我正在修复一些已出现的错误。 显然 substring(from:)' 已被弃用。使用带有“部分范围”运算符的字符串切片下标

t_prefix_phone = contact_phone.substring(to:contact_phone.index(contact_phone.startIndex, offsetBy: 3))

t_phone = contact_phone.substring(from:contact_phone.index(contact_phone.endIndex, offsetBy: -7))

你能帮我把上面的代码翻译成 4.2,这样结果仍然是字符串。

谢谢

【问题讨论】:

标签: swift4.2 xcode10.1


【解决方案1】:

swift 4 有前缀和后缀:

    let contact_phone = "0123456789"
    let t_prefix_phone = String(contact_phone.prefix(3))
    let t_phone = String(contact_phone.suffix(7))

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 1970-01-01
    • 2018-02-05
    • 2023-03-28
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    相关资源
    最近更新 更多