Vemonus Vemonus - 4 months ago 28
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?


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)