我有以下用Swift 3编写的简单代码:
let str = "Hello, playground"
let index = str.index(of: ",")!
let newStr = str.substring(to: index)
Run Code Online (Sandbox Code Playgroud)
从Xcode 9 beta 5,我得到以下警告:
'
substring(to:)'已被弃用:请使用String带有'partial range from'运算符的切片下标.
如何在Swift 4中使用具有部分范围的切片下标?