After converting my Swift 3 project to Swift 4 I received the warning:

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

The old Swift 3 code was

let str = "Some String"
let range = str.range(of:"Some ")
let index = range!.upperBound
let subStr = str.substring(from: index)

The new Swift 4 code for substring is:

let str = "Some String"
let range = str.range(of:"Some ")
let index = range!.upperBound
let subStr = String(str[index...])
Swift 4 substring
Translate »