加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

不推荐使用Swift 4’substring(from :)’:请使用字符串切片下标

发布时间:2020-12-14 05:49:08 所属栏目:百科 来源:网络整理
导读:我刚刚转换了我的小应用程序,但我发现了这个错误: ‘substring(from :)’不推荐使用:请使用字符串切片下标和’partial range from’运算符 我的代码是: let dateObj = dateFormatterFrom.date(from: dateStringa) if dateObj != nil { cell.detailTextLab
我刚刚转换了我的小应用程序,但我发现了这个错误:
‘substring(from :)’不推荐使用:请使用字符串切片下标和’partial range from’运算符

我的代码是:

let dateObj = dateFormatterFrom.date(from: dateStringa)


    if dateObj != nil {
        cell.detailTextLabel?.text = dateFormatterTo.string(from:(dateObj!))
    } else {
        let index = thisRecord.pubDate.index(thisRecord.pubDate.startIndex,offsetBy: 5)
        cell.detailTextLabel?.text = thisRecord.pubDate.substring(from: index)
    }
代替子串使用后缀.使用如下:
cell.detailTextLabel?.text = String(thisRecord.pubDate.suffix(from: index))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读