Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm glad to see that my code is proving useful! :)</p> <p><code>CHCSVParser</code> is similar in behavior to an <code>NSXMLParser</code>, in that every time it finds something interesting, it's going to let you know via one of the delegate callbacks. However, if you choose to ignore the data that it gives you in the callback, then it's gone. These parsers (<code>CHCSVParser</code> and <code>NSXMLParser</code>) are pretty stupid. They just know the format of the stuff they're trying to parse, but don't really do much beyond that.</p> <p>So the answer, in a nutshell, is "you have to save it yourself". If you look at the code for the <code>NSArray</code> category, you'll see in the .m file that it's using <a href="http://github.com/davedelong/CHCSVParser/blob/master/NSArray%2BCHCSVAdditions.m#L30" rel="noreferrer">a simple <code>NSObject</code> subclass as the parser delegate</a>, and that subclass is what's aggregating the fields into an array, and then adding that array to the overall array. You'll need to do something similar.</p> <p>Example delegate:</p> <pre><code>@interface CSVParserDelegate : NSObject &lt;CHCSVParserDelegate&gt; { NSMutableArray * currentRow; } @end @implementation CSVParserDelegate - (void) parser:(CHCSVParser *)parser didStartLine:(NSUInteger)lineNumber { currentRow = [[NSMutableArray alloc] init]; } - (void) parser:(CHCSVParser *)parser didReadField:(NSString *)field { [currentRow addObject:field]; } - (void) parser:(CHCSVParser *)parser didEndLine:(NSUInteger)lineNumber { NSLog(@"finished line! %@", currentRow); [self doSomethingWithLine:currentRow]; [currentRow release], currentRow = nil; } @end </code></pre> <p>However, I could be convinced to modify the behavior of the parser to aggregate the row itself, but if I go down that route, why not just have the parser aggregate the entire file? (Answer: it shouldn't)</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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