Note that there are some explanatory texts on larger screens.

plurals
  1. POCHCSVParser returns nil Array for valid filePath & valid csv file
    primarykey
    data
    text
    <p>I am trying to parse a .csv file with approximately 30K lines. The following was mycode:</p> <pre><code>NSString *pathToGameLibrary = [[NSBundle mainBundle] pathForResource:@"GameLibrarySample" ofType:@"csv"]; NSArray *gameLibraryData = [NSArray arrayWithContentsOfCSVFile:pathToGameLibrary]; </code></pre> <p>At the end of this execution, gameLibraryData is nil.</p> <p>I can confirm that both the path and the csv file are valid because the following code spits out 30,000 lines of data to the console:</p> <pre><code>NSString *pathToGameLibrary = [[NSBundle mainBundle] pathForResource:@"GameLibrarySample" ofType:@"csv"]; NSString *fileString = [NSString stringWithContentsOfFile:pathToGameLibrary encoding:NSUTF8StringEncoding error:nil]; NSLog(@"%@", fileString); </code></pre> <p>Because this code does not work, I assume that the failure has to do with the length of the csv file. In an <a href="https://stackoverflow.com/questions/4636428/load-remote-csv-into-chcsvparser">earlier question</a>, CHCSV's author Dave DeLong suggests that:</p> <blockquote> <p>"If this is a very big file, then you'll want to alloc/init a CHCSVParser with the path to the local copy of the CSV file."</p> </blockquote> <p>So...I've tried to follow what <a href="https://stackoverflow.com/questions/4636428/load-remote-csv-into-chcsvparser">the original poster</a> attempted with this code:</p> <pre><code>NSString *pathToGameLibrary = [[NSBundle mainBundle] pathForResource:@"GameLibrarySample" ofType:@"csv"]; CHCSVParser *file = [[CHCSVParser alloc] initWithContentsOfCSVFile:pathToGameLibrary]; [file setDelegate:self]; </code></pre> <p>At which point the method callbacks which enable retrieval of data are:</p> <pre><code>- (void)parserDidBeginDocument:(CHCSVParser *)parser; - (void)parserDidEndDocument:(CHCSVParser *)parser; - (void)parser:(CHCSVParser *)parser didBeginLine:(NSUInteger)recordNumber; - (void)parser:(CHCSVParser *)parser didEndLine:(NSUInteger)recordNumber; - (void)parser:(CHCSVParser *)parser didReadField:(NSString *)field atIndex:(NSInteger)fieldIndex; - (void)parser:(CHCSVParser *)parser didReadComment:(NSString *)comment; - (void)parser:(CHCSVParser *)parser didFailWithError:(NSError *)error; </code></pre> <p>Thanks to yonosoytu for le assistance.</p> <p>On Topic Post-Edit Question: So what counts as a "very big file" anyway? At which point is it prudent to use delegation over the simple 'arrayWithContentsofCSVFile'?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload