Created
July 20, 2013 20:25
-
-
Save dmdeller/6046312 to your computer and use it in GitHub Desktop.
CHCSVParser with blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HNCSVParser.h | |
// HNCSVParser | |
// | |
// Created by David on 7/20/13. | |
// Copyright (c) 2013 David Deller. MIT Licensed. | |
// | |
#import <CHCSVParser/CHCSVParser.h> | |
@interface HNCSVParser : CHCSVParser <CHCSVParserDelegate> | |
@property (copy) void (^didBeginDocument)(); | |
@property (copy) void (^didEndDocument)(); | |
@property (copy) void (^didBeginLine)(NSUInteger recordNumber); | |
@property (copy) void (^didEndLine)(NSUInteger recordNumber); | |
@property (copy) void (^didFailWithError)(NSError *error); | |
@property (copy) void (^didReadComment)(NSString *comment); | |
@property (copy) void (^didReadField)(NSString *field, NSInteger fieldIndex); | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HNCSVParser.m | |
// HNCSVParser | |
// | |
// Created by David on 7/20/13. | |
// Copyright (c) 2013 David Deller. MIT Licensed. | |
// | |
#import "HNCSVParser.h" | |
@implementation HNCSVParser | |
- (id)initWithInputStream:(NSInputStream *)stream usedEncoding:(NSStringEncoding *)encoding delimiter:(unichar)delimiter | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
self.delegate = self; | |
} | |
return self; | |
} | |
#pragma mark - | |
- (void)parserDidBeginDocument:(CHCSVParser *)parser | |
{ | |
if (self.didBeginDocument != nil) self.didBeginDocument(); | |
} | |
- (void)parserDidEndDocument:(CHCSVParser *)parser | |
{ | |
if (self.didEndDocument != nil) self.didEndDocument(); | |
} | |
- (void)parser:(CHCSVParser *)parser didBeginLine:(NSUInteger)recordNumber | |
{ | |
if (self.didBeginLine != nil) self.didBeginLine(recordNumber); | |
} | |
- (void)parser:(CHCSVParser *)parser didEndLine:(NSUInteger)recordNumber | |
{ | |
if (self.didEndLine != nil) self.didEndLine(recordNumber); | |
} | |
- (void)parser:(CHCSVParser *)parser didFailWithError:(NSError *)error | |
{ | |
if (self.didFailWithError != nil) self.didFailWithError(error); | |
} | |
- (void)parser:(CHCSVParser *)parser didReadComment:(NSString *)comment | |
{ | |
if (self.didReadComment != nil) self.didReadComment(comment); | |
} | |
- (void)parser:(CHCSVParser *)parser didReadField:(NSString *)field atIndex:(NSInteger)fieldIndex | |
{ | |
if (self.didReadField != nil) self.didReadField(field, fieldIndex); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment