Comments (3)
Here's the code I'm using in my delegate.
- (void)parser:(CHCSVParser *)parser didReadField:(NSString *)field atIndex:(NSInteger)fieldIndex
{
// SKIP: Undefined keyCol and valueCol (both are likely 0)
if(self.keyCol == self.valueCol)
return;
// Set the key in temporary keyObject
if(fieldIndex == self.keyCol)
{
self.keyObject = field;
}
// Set the key --> value pair
if(fieldIndex == self.valueCol && self.keyObject && field)
{
[self.mapDict setObject:field forKey:self.keyObject];
// Reset key (value is temporary)
self.keyObject = nil;
}
}
from chcsvparser.
And...
-(NSDictionary*)dictionaryWithKeysColumn:(NSInteger)keyColumn valueColumn:(NSInteger)valueColumn
{
self.mapDict = [[NSMutableDictionary alloc] init];
self.keyCol = keyColumn;
self.valueCol = valueColumn;
[self parse];
self.keyCol = 0;
self.valueCol = 0;
return self.mapDict;
}
-(void)parse
{
self.csvParser = nil;
[self.csvParser parse];
}
-(CHCSVParser*)csvParser
{
if(!_csvPathForResource)
{
NSLog(@"%s - error, missing csvPathForResource", __PRETTY_FUNCTION__);
return nil;
}
if(!_csvParser)
{
NSString *csvFilePath = [[NSBundle mainBundle] pathForResource:self.csvPathForResource
ofType:@"csv"
inDirectory:self.csvDirForResource];
if(csvFilePath)
_csvParser = [[CHCSVParser alloc] initWithContentsOfCSVFile:csvFilePath];
NSLog(@"%s - created _csvParser:%@", __PRETTY_FUNCTION__, _csvParser);
}
return _csvParser;
}
from chcsvparser.
DOH. I was on the right track... Deallocating works. However, my code above didn't set the delegate back to self. I added one more line to the lazy loading -csvParser method.
-(CHCSVParser*)csvParser
{
if(!_csvPathForResource)
{
NSLog(@"%s - error, missing csvPathForResource", __PRETTY_FUNCTION__);
return nil;
}
if(!_csvParser)
{
NSString *csvFilePath = [[NSBundle mainBundle] pathForResource:self.csvPathForResource
ofType:@"csv"
inDirectory:self.csvDirForResource];
if(csvFilePath)
{
_csvParser = [[CHCSVParser alloc] initWithContentsOfCSVFile:csvFilePath];
_csvParser.delegate = self;
}
NSLog(@"%s - created _csvParser:%@", __PRETTY_FUNCTION__, _csvParser);
}
return _csvParser;
}
from chcsvparser.
Related Issues (20)
- Four warnings when I build. Xcode 7.3, targeting iOS 8 or later. HOT 4
- issue with (ΒΊ)degree symbol at time of export HOT 2
- When open a csv file in appending mode, set the _currentLine the last line number of the file
- Exception raised when using -writeLineWithDictionary: to append records
- Fails to parse line with backslashed quotes, even with 'recognize backslashes' option
- Swift delegate prototypes (a comment, not an issue) HOT 2
- Parsed Data Replaces Double Quotes with Two Sets of Double Quotes HOT 1
- unable to parse csv file with initWithContentsOfCSVFile HOT 1
- Fails to parse record with unescaped parenthesis HOT 10
- Parsing ends if field includes nullchar HOT 1
- Thoughts on providing SAX style parsing
- The parser doesn't see field when it contains unescaped '\n' HOT 1
- Two warnings when building using XCode 7 Beta 5 HOT 16
- tvos support HOT 2
- NSInputStream inputStreamWithURL always nil HOT 1
- Using the 3.0.0 Version in Swift HOT 1
- Output parsing to an Array? HOT 1
- writeField:(id)field raises exception if first line of CSV has any null field HOT 1
- Typo in readme.markdown
- Use a proper CSV writer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chcsvparser.