I’m attempting to write a large CSV file, from a core data managed object to the apps documents directory using CHCSVWriter.
While it seems runs fine, the cvs file doesn’t seem to exist once completed.
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = @"productFileExport.csv";
NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];
CHCSVWriter *cvsExport = [[CHCSVWriter alloc] initWithCSVFile:[fileURL absoluteString] atomic:NO];
for (Product *prod in fetchedObjects) {
[cvsExport writeLineOfFields:prod.code, prod.barcode, prod.name, prod.size, prod.casesize, nil];
}
[cvsExport closeFile];
I believe it to be an issue with the filename i’ve tried changing the initWithCVSFile: from [fileURL absoluteString] to [fileURL path] and [fileURL description] with no luck.
Also if i change atomic to YES it get the following error:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[NSFileManager
moveItemAtPath:toPath:error:]: destination path is nil’
Any help would be greatly appreciated, thanks
The problem was in the
cvsExport writeLineOfFieldsthe first object being passed was nil so nothing was getting written to the file.also the
initWithCVSFile:required[fileURL path]to be passed to it.