Skip to content

Instantly share code, notes, and snippets.

@alsedi
Last active February 8, 2017 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alsedi/ef873fdd7ee6294702082b6cb68c9d26 to your computer and use it in GitHub Desktop.
Save alsedi/ef873fdd7ee6294702082b6cb68c9d26 to your computer and use it in GitHub Desktop.
import Foundation
let content = "abc,cde,5.5,128,256\nefg,ghi,42"
let parsedCSV: [[CustomStringConvertible]] = content
.components(separatedBy: "\n")
.map({
$0.components(separatedBy: ",")
.filter({ Int($0) != nil })
})
print(parsedCSV)
//[["128", "256"], ["42"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment