我的旧代码是:
let comps = split(str, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false)
更新Swift 2后,我的XCode 7将其修复为:
let comps = split(str.characters, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false).map { String($0) }
但现在我遇到了错误:Cannot invoke 'map' with an argument list of type '((_) -> _)'
如何修复它。
答案 0 :(得分:1)
split()
函数的参数顺序由于某种原因搞砸了。它应该是:
let comps = split(str.characters, maxSplit: Int.max, allowEmptySlices: false) {
$0 == "-" || $0 == " "
}.map {
String($0)
}