0

I am mapping my university and they provide a .csv file with a list of all of the buildings on campus. Which includes information like Building #, Name, Code, Street address, Street coordinate ect.

I want to read the values from this file to create a NSArray of Building objects. This is how the file is formatted, how would I go about doing this?

enter image description here

1 Answer 1

1

Load the csv into a NSString.

NSString *path = [[NSBundle mainBundle] pathForResource:@"filename"
                                                 ofType:@"csv"];

NSStringEncoding encoding = 0;
NSError *error = nil;
NSString *csvString = [NSString stringWithContentsOfFile:path
                                            usedEncoding:&encoding
                                                   error:&error];

Parse it with your preferred method, I use an open source library, CHCSVParser https://github.com/davedelong/CHCSVParser

NSArray *fields = [csvString CSVComponents]; // you need to import "CHCSVParser.h"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.