Search code examples
xcodeswiftios9

XCode 7 join is deprecated


I just downloaded the XCode 7 GM seed. It complains about the join method on String. How do I use joinWithSeparator instead of join?

//1            
// Create an `NSCharacterSet` set which includes everything *but* the digits
let inverseSet = NSCharacterSet(charactersInString:"0123456789").invertedSet

//2
// At every character in this "inverseSet" contained in the string,
// split the string up into components which exclude the characters
// in this inverse set
let components = string.componentsSeparatedByCharactersInSet(inverseSet)

//3            
// Rejoin these components
let filtered = "".join(components)

Solution

  • Soon after I figured it out, in case you are stuck on the same problem.

    replace 3rd step with the line below

    let filtered = components.joinWithSeparator("")