warning: 'characters' is deprecated: Please use String or Substring directly
characters - an instance property of String, is deprecated from with Xcode 9.1
It was very useful to get a substring from String by using the characters
property but now it has been deprecated and Xcode suggests to use substring
. I've tried to check around SO questions and apple developer tutorials/guidelines for the same. But could not see any solution/alternate as suggested.
Here is warning message:
'characters' is deprecated: Please use String or Substring
I've so many string operations are performed/handled using property characters
.
Anyone have any idea/info about this update?
Solution 1:
Swift 4 introduced changes on string API.
You can just use !stringValue.isEmpty
instead of stringValue.characters.count > 0
for more information you get the sample from here
for e.g
let edit = "Summary"
edit.count // 7
Solution 2:
Swift 4 vs Swift 3 examples:
let myString = "test"
for char in myString.characters {print(char) } // Swift 3
for char in myString { print(char) } // Swift 4
let length = myString.characters.count // Swift 3
let length = myString.count // Swift 4