不推荐使用XCode 7 join

问题描述 投票:0回答:2

我刚下载了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)
xcode swift ios9
2个回答
1
投票

我想出来后不久,以防你遇到同样的问题。

用下面的行替换第3步

let filtered = components.joinWithSeparator(“”)


-1
投票
let inverseSet =
    NSCharacterSet(charactersInString:"0123456789+").invertedSet   
let components = string.componentsSeparatedByCharactersInSet(inverseSet)
//let filtered = join("", components) 
let filtered = components.joinWithSeparator("") //swift2.0change
© www.soinside.com 2019 - 2024. All rights reserved.