Swift 2 - 在字符串中搜索并对数字求和

Swift 2 - Search in string and sum the numbers

我的旧代码是:

let comps = split(str, { [=11=] == "-" || [=11=] == " " }, maxSplit: Int.max, allowEmptySlices: false)

更新 Swift 2 后,我的 XCode 7 将其修复为:

let comps = split(str.characters, { [=12=] == "-" || [=12=] == " " }, maxSplit: Int.max, allowEmptySlices: false).map { String([=12=]) }

但现在我有一个错误:Cannot invoke 'map' with an argument list of type '((_) -> _)'

如何解决。

Link to old answer on Swift

split() 函数的参数顺序由于某种原因搞乱了。应该是:

let comps = split(str.characters, maxSplit: Int.max, allowEmptySlices: false) {
    [=10=] == "-" || [=10=] == " "
}.map {
    String([=10=])
}