Swift 4 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator

前端 未结 7 2109
情话喂你
情话喂你 2020-12-30 23:59

i\'ve just converted my little app but i\'ve found this error: \'substring(from:)\' is deprecated: Please use String slicing subscript with a \'partial range from\' operator

7条回答
  •  误落风尘
    2020-12-31 00:21

    If you wish to get substring with specific offset without upper bound do the following:

    let index = thisRecord.pubDate.index(thisRecord.pubDate.startIndex, offsetBy: 5)
    cell.detailTextLabel?.text = String(thisRecord.pubDate[index...]
    

    This way you create a new String object from your existing String thisRecord.pubDate taking anything from specified index to the end index of original String.

提交回复
热议问题