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

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


Follow the below example to fix this warning:Supporting examples for Swift 3, 4 and 5.

let testStr =Test Tejalet finalStr = testStr.substring(to: index) // Swift 3let finalStr = String(testStr[..<index]) // Swift 4let finalStr = testStr.substring(from: index) // Swift 3let finalStr = String(testStr[index...]) // Swift 4 //Swift 3let finalStr = testStr.substring(from: index(startIndex, offsetBy: 3)) //Swift 4 and 5let reqIndex = testStr.index(testStr.startIndex, offsetBy: 3)let finalStr = String(testStr[..<reqIndex])//**Swift 5.1.3 - usage of index**let myStr = "Test Teja == iOS"let startBound1 = String.Index(utf16Offset: 13, in: myStr)let finalStr1 = String(myStr[startBound1...])// "iOS"let startBound2 = String.Index(utf16Offset: 5, in: myStr)let finalStr2 = String(myStr[startBound2..<myStr.endIndex]) //"Teja == iOS"


In place of substring use suffix. Use like below :

cell.detailTextLabel?.text = String(thisRecord.pubDate.suffix(from: index))


It means you should use the new partial range operator as your upperBound:

let str =  "Hello World !!!"if let index = str.range(of: "Hello ")?.upperBound {   let string = String(str[index...])  // "World !!!"}

In your case

cell.detailTextLabel?.text = String(thisRecord.pubDate[index...]))