I am currently trying to use CHCSVParser to parse CSV files containing more than 1500 records and 8 lines. I was able to parse the file and I am getting NSArray from NSArrays from NSStrings.
For example, here is what I get:
Loading CSV from: (
(
Last,
First,
Middle,
Nickname,
Gender,
City,
Age,
Email
),
(
Doe,
John,
Awesome,
"JD",
M,
"San Francisco",
"20",
"john@john.doe"
),
How can I sort this in a Person object and filter it using NSPredicate, for example, MattT Thompson does here .
This is how I initialize the parser:
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"myFile" ofType: @"csv"];
NSArray *myFile = [NSArray arrayWithContentsOfCSVFile:pathToFile options:CHCSVParserOptionsSanitizesFields];
NSLog(@"Loading CSV from: %@", myFile);
Here's what Matt does in the article I linked that I would like to do with my code:
NSArray *firstNames = @[ @"Alice", @"Bob", @"Charlie", @"Quentin" ];
NSArray *lastNames = @[ @"Smith", @"Jones", @"Smith", @"Alberts" ];
NSArray *ages = @[ @24, @27, @33, @31 ];
NSMutableArray *people = [NSMutableArray array];
[firstNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
Person *person = [[Person alloc] init];
person.firstName = firstNames[idx];
person.lastName = lastNames[idx];
person.age = ages[idx];
[people addObject:person];
}];