swift2 - Swift array.map - cannot invoke 'map' -
i using following code in xcode 6.4 split strings inside array arrays:
func getdata() -> [string] { let data = navdata // navdata like: // a|xxx|xxx|xxx // r|ccc|ccc|ccc // n|ccc|ccc|ccc // n|ccc|ccc|ccc return split(data) { $0 == "\n" } } let data:[string] = getdata() func search(query:(string, int)) -> [string] { let recs:[string] = data.filter { $0.hasprefix(query.0) } var cols: [string] = recs.map { split( recs ) { $0 == "|" } } } func searchqueries() -> [(string, int)] { return [("n", 1)] //key, column index } q:(string, int) in searchqueries() { var results:[string] = search(q) x in results { result = results[0] } }
it used work before, guess swift changed in 1.2 , gives following error now:
cannot invoke 'map' argument list of type '(() -> _)'
any suggestions?
thank you!
after discovering in swift 2 have split strings using characters
property, made work in playground:
let recs = ["col1|col2|col3", "1|2|3"] let cols = recs.map { split($0.characters) { $0 == "|" }.map {string($0)} } cols.first // ["col1", "col2", "col3"] cols.last // ["1", "2", "3"]
note in swift 2 beta 2 can use {string.init}
@ end.
to make work in swift 1.2, remove .characters
.
Comments
Post a Comment