问题
My old code was:
let comps = split(str, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false)
after update of Swift 2 my XCode 7 fix it to:
let comps = split(str.characters, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false).map { String($0) }
but now I have an error: Cannot invoke 'map' with an argument list of type '((_) -> _)'
How to fix it.
Link to old answer on Swift
回答1:
The order of arguments for split()
function messed up for some reason. It should be:
let comps = split(str.characters, maxSplit: Int.max, allowEmptySlices: false) {
$0 == "-" || $0 == " "
}.map {
String($0)
}
来源:https://stackoverflow.com/questions/31224936/swift-2-search-in-string-and-sum-the-numbers