You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a better, professional and well tested version of this quick hackery I made a few days ago.
The idea is that anything that is:
a RangeReplacableCollection,
who's elements are RangeReplacableCollections
who's subitems are ExpressibleByStringLiteral
can all be initialized from a CSV.
The additional stuff to add:
Anything that is expressible by an array literal
Bunch of tests
Bunch of examples
import Foundation
typealiasRawCsvTable=[[String]]extensionRangeReplaceableCollectionwhere
Element:RangeReplaceableCollection,
Element.Element:ExpressibleByStringLiteral,
Element.Element.StringLiteralType ==String{typealiasCsvTable=SelftypealiasCsvRow=ElementtypealiasCsvCell=Element.Elementinit?(fromCsv url:URL){
guard let raw =try?String(contentsOf: url)else{returnnil}self.init(
raw
.components(separatedBy:.newlines).map{.init($0.components(separatedBy:";").map{CsvCell(stringLiteral: $0)})})}}
The text was updated successfully, but these errors were encountered:
Add a better, professional and well tested version of this quick hackery I made a few days ago.
The idea is that anything that is:
RangeReplacableCollection
,RangeReplacableCollection
sExpressibleByStringLiteral
can all be initialized from a CSV.
The additional stuff to add:
The text was updated successfully, but these errors were encountered: