我刚下载了XCode 7 GM种子。它抱怨String上的join方法。如何使用joinWithSeparator而不是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)
我想出来后不久,以防你遇到同样的问题。
用下面的行替换第3步
let filtered = components.joinWithSeparator(“”)
let inverseSet =
NSCharacterSet(charactersInString:"0123456789+").invertedSet
let components = string.componentsSeparatedByCharactersInSet(inverseSet)
//let filtered = join("", components)
let filtered = components.joinWithSeparator("") //swift2.0change