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

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

swift4更新了字符串操作的API方法 特此记录一波
substring方法被标记为过时。。其实还不怎么会用呢就。。

let urlStr = "tel://114"
if let rangeIndex = urlStr.range(of: "tel://") {
      let number = urlStr[rangeIndex.upperBound...] //substring(from: rangeIndex.upperBound)
      print("number is :\(number)")
}

可以看到字符串urlStr被当做字符数组来处理 但是直接通过下标来获取是不行的 如下:


481508830941_.pic.jpg

必须是CountablePartialRangeFrom这种类型的下标,以后有空再研究:)

你可能感兴趣的:('substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.)