Hi all,
I have an app that imports a .CSV file and turns each line into a Core Data object that is stored in a database. The CSV files that I am importing have about 40-something columns and each column maps to an attribute of the Core Data object.
When I started the project, there was only one CSV format that I was working with, so I just wrote 40-something lines of un-elegant static code to import the file, such as:
...
newEntity.yearOfConstruction = [NSNumber numberWithInt:[[currentRow objectAtIndex:35] integerValue]];
newEntity.assessedValue = [NSNumber numberWithInt:[[currentRow objectAtIndex:36] integerValue]];
newEntity.squareFootageOfProperty = [NSNumber numberWithInt:[[currentRow objectAtIndex:37] integerValue]];
...
Now the problem that I've run into is that I would like to import other CSV file formats that are ordered differently than those in my original use case.
Rather than write a switch(CSVFormatType)
and add additional 40-line sets of code, what is the elegant way to store the CSV column-to-Core Data mapping for an arbitrary number CSV file types and just one set of code to create the Core Data objects?
Thanks!