Vemonus Vemonus - 1 year ago 92
Swift Question

What is the new way to trim a String?

Prior to being forced to switch to Swift 3.0 syntax, the following line worked just fine:

return urlString.stringByTrimmingCharactersInSet(unwantedChars)

However, having updated to Swift 3.0, it now prevents me from building my app in Xcode, showing me the error message
Value of Type 'String' has no member 'StringByTrimmingCharactersInSet'
. What is the new syntax for this?

Answer Source

Swift3 inctroduced a lot of changes shortening api names and making them more 'swiftly'. Your code would look the following in swift3:

let st = s.trimmingCharacters(in: unwantedChars)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download