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
Hello. I was looking to have a CSV file that gets updated every time a user performs an action in an app. I also wanted the CSV file to contain a header row.
Subsequent appends won't be started on a new line because isFirstRow is defaulted to true, causing write to ignore the configuration.newline.unicodeScalars.forEach(writeScalar) call.
I thought I could just add a beginNewRow() call, but it technically doesn't modify the steam
Here is the code I was trying:
let exists = FileManager.default.fileExists(atPath: url.path)
let stream = OutputStream(url: url, append: true)!
let csv = try! CSVWriter(stream: stream)
if !exists {
try! csv.write(row: ["Date", "Question 1", "Question 2", "Question 3"])
}
try! csv.write(row: [rfcDate, answer1, answer2, answer3])
csv.stream.close()
The text was updated successfully, but these errors were encountered:
Is it normal in a MacOS environment for CSV files NOT to be newline terminated?
I'm used to expecting CSV files to end with a newline (or CRLF), so if I created an OutputStream on such a file, this library would correctly append new lines - but leave me with a stream that no longer ends with a newline and hence require, as you do above, manually adding one before appending further lines.
If there really is a need to produce CSV files that aren't newline terminated, I suppose it could be an option (but I'd expect it to do by default).
Hello. I was looking to have a CSV file that gets updated every time a user performs an action in an app. I also wanted the CSV file to contain a header row.
Subsequent appends won't be started on a new line because isFirstRow is defaulted to true, causing write to ignore the configuration.newline.unicodeScalars.forEach(writeScalar) call.
I thought I could just add a beginNewRow() call, but it technically doesn't modify the steam
Here is the code I was trying:
The text was updated successfully, but these errors were encountered: