Hi @Josedv
I'm working on an app with csv read functionality (tapping on a button to open share extension and read a file from Files/...). I managed to find the following in some other thread, which works(ish) for me (I'll explain the ish).
I totally agree with @eskimo that you should enforce some sort of formatting rule wherever csv files are generated (this was an ongoing pain at one of my previous jobs), and another pain was to verify the validity of the content, but I guess that's another conversation?
It's available from
https://github.com/ahltorp/csvparserI used it with Swift 5, and it reads my csv file properly.
My csv file was generated using commas as delimiter, nested data as header/detail report style and column order as original.
So the ish part, it generates an array of arrays of String (
[[String]]), with the first item being the titles for each column (this is particularly useful because this determines the number of columns too, even if one of the rows in that column has an invalid value, I think).
I had to create some sort of verifier (to determine whether we have correct number of
Strings in each row), and an adaptor for iterating through each inner array items and create my objects from it.
I guess the above link can be further improved by compiling data received into
dictionaries/json which can then be converted to
Data, and that data can then be provided in a generic form.
I'll try to do that and put it on Github, but this should unblock you (not sure if it's any longer relevant).
Best wishes, and if you have any further updates, please let me know