nero5023 / csvparser Goto Github PK
View Code? Open in Web Editor NEWA swift package for read and write CSV file
License: MIT License
A swift package for read and write CSV file
License: MIT License
extension CSVParser: RangeReplaceableCollection {
public func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where C : Collection, C.Iterator.Element == Array<String> {
self._rows.replaceSubrange(subrange, with: newElements)
}
public func reserveCapacity(_ n: Int) {
self._rows.reserveCapacity(n)
}
}
Here i have got error.
Hi there!
I'm trying to initialize a CSVParser from a String and I'm getting a fatal error.
Line 29 of parser.swift
is if inputContents[cursor] == quotes {
This line is throwing fatal error: Can't form a Character from an empty String
inputContents[cursor]
and quotes
are both equal to a single "
and I've tried several things trying to debug this but got nowhere.
This is the string I'm passing to the initializer with let csvParser = try CSVParser(content: csvString)
is:
"Subject 1 #hashtagone","http://example.com/one"
"Subject 2 #hashtagtwo","http://example.com/two"
"Subject 3 #hashtagthree","http://example.com/three"
Any ideas?
I got an error when running an app on Ubuntu.
Fatal error: init(contentsOfFile:usedEncoding:) is not yet implemented: file Foundation/NSString.swift, line 1308
It's caused by this line
public convenience init(filePath: String, delimiter: Character = ",", lineSeparator: Character = "\n") throws {
let fileContent = try String(contentsOfFile: filePath) // <-- this line
try self.init(content: fileContent, delimiter: delimiter, lineSeparator: lineSeparator)
}
You should consider to use the same method with explicit encoding
.
Following code works well on Ubuntu:
let fileContent = try String(contentsOfFile: filePath, encoding: .utf8)
its only parsing 6750 rows out of 30000 rows
Whenever one of my project is run with CSVParser as one of its frameworks (and even when it is the only framework used in the entire project), and run on an actual iPhone, the error "This Application's bundle identifier does not match its code signing identifier". Are there any solutions to this problem by anyone?
When i try to Write data
let csv = try CSVParser(filePath: "path/to/csvfile")
// get every row in csv
below line throws an error after updating to 4.1
csv[0] = ["test0", "test1", "test2"] // **Cannot assign through subscript: subscript is get-only**
csv.wirite(toFilePath: "path/to/destination/file")
Could you set an explicit iOS target version to something like 8.0 9.0 for backwards compatibility, because while building with Carthage it assumes its latest version which does not allow for backwards compatibility at least 1 or ideally two versions back like 9 or 8.
Thanks!
Hello
Please let me know how to create new csv file.
Thanks.
There is no Podspec for use with CocoaPods.
Please add the podspec.
If there is a blank line at the end of a file/string, a row that contains ["\r"]
is created.
It would be nice to be able to have headers parsed separately from rows(if the file has headers) so you could do something like let csv = CSVParser(content: string, hasHeaders: true)
and then be able to let headers = csv.headers
and let rows = csv.rows
Hi !
So, excel being excel, it exports utf-8 csv using semi-columns (;) characters as delimiters, and \r as line separators.
So I specified those as such... and running crashes the program in Xcode, hitting a breakpoint in the CFHash thread, before stopping with
Message from debugger: Terminated due to signal 9
I don't have any breakpoint in my code, and CSVParser is the only framework I'm using.
Any idea ?
Just in case, here's my function
func importCSV(filePath: String) {
do {
let delimeter: Character = ";"
let lineSeparator: Character = "\r"
let csv = try CSVParser(filePath: filePath, delimiter: delimeter, lineSeparator: lineSeparator)
var i = 0
for row in csv {
print("Row \(i): \(row)\n") // ["first column", "sceond column", "third column"]
i += 1
}
do {
let jsonStr = try csv.toJSON()
consoleIO.writeMessage("json: \(jsonStr)")
} catch let csvToJsonError {
consoleIO.writeMessage(csvToJsonError.localizedDescription, to: .error)
}
} catch let error {
print(error)
consoleIO.writeMessage(error.localizedDescription, to: .error)
}
}
Using a random character as delimiter (such as "j") makes it work just fine... almost.
csv.toJSON() fails on the enumeratedWithDic() function, but I guess it's because there aren't any headers (since "j" isn't really a delimiter in the csv file ^^")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.