Swift 2 - Search in string and sum the numbers

霸气de小男生 提交于 2019-12-20 05:43:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!