1. 程式人生 > >xcode9 以上,黃色警告處理!

xcode9 以上,黃色警告處理!

警告:'characters' is deprecated: Please use String or Substring directly

self.characters.count

解決:

let edit ="Summary"
edit.count   // 

警報:'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.

self.substring(to: self.index(of: Character(eT))!)


解決:

You should leave one side empty

, hence the name "partial range".

let newStr = str[..<index]

The same stands for partial range from operators, just leave the other side empty:

let newStr = str[index...]

Keep in mind that these range operators return a Substring. If you want to convert it to a string, use String's initialization function:

let newStr =String(str[..<index])

You can read more about the new substrings here.