How to export data to a csv file with iOS?

You can also do something like:

[[array componentsJoinedByString:@","] writeToFile:@"components.csv" atomically:YES encoding:NSUTF8StringEncoding error:NULL];

You can use combinations of this to put together a CSV (append the output of one array for the column names to one array for the values, etc).

Of course, you have to be careful to put quotes around values that already contain a comma, and to then escape any quotes in the value.

Leave a Comment