Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't write CSV file using CHCSVParser (CHCSVWriter)

I want to export data from my application into a csv file.

I found CHCSVParser by Dave Delong

https://github.com/davedelong/CHCSVParser

I created a test project, imported CHCSVWriter and wrote this:

CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:@"~/testfile.csv" atomic:NO];
    [csvWriter writeField:[NSString stringWithFormat:@"One"]];
    [csvWriter writeLine];
    [csvWriter writeField:[NSString stringWithFormat:@"Two"]];
    [csvWriter writeLine];
    [csvWriter closeFile];
    [csvWriter release];

But I get no testfile.csv in the Finder :(

What am I doing wrong?

like image 218
Daniel Avatar asked Apr 17 '26 01:04

Daniel


1 Answers

You will need to expand the ~ for this to work. You can either update the parser to handle the ~ for you or you can initialize the parser like this,

NSString * filePath = @"~/testfile.csv";
filePath = [filePath stringByExpandingTildeInPath];

CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:filePath atomic:NO];
like image 62
Deepak Danduprolu Avatar answered Apr 20 '26 23:04

Deepak Danduprolu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!