I am new to coding, so please excuse me if this seems like a simple question.
I am trying to plot coordinates on a map.
I want to read a CSV file and pass the information into two separate arrays.
The first array will be NSArray * towerInfo (containing latitude, longitude and tower name)
the second NSArray * region (containing the name and region of the tower) with the same reference index as the first array.
Essentially, I think I need:
1) read the file on the line .....
2) divide the string into a temporary array dividing on each / n / r ......
3) scroll through the temp array and each time create a Tower and Region object before adding this information to the two main storage arrays.
Is this the right process, and if so, is there anyone who can post some sample code, as I am really trying to figure it out.
Thanks to everyone in advance.
Chris.
I edited this to show an example of my code. I'm having a problem getting warnings saying
1) the "local declaration 'dataStr' hides the instance variable. 2) the" local declaration "array" hides the instance variable.
I think I understand what this means, but I don’t know how to get around this. The program compiles and runs, but the log tells me that "the array is null."
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize dataStr;
@synthesize array;
-(IBAction)convert {
NSString *dataStr = [NSString stringWithContentsOfFile:@"Towers.csv" encoding:NSUTF8StringEncoding error:nil];
NSArray *array = [dataStr componentsSeparatedByString: @","];
NSLog(@"array: %@", array);
}
Any further help would be greatly appreciated. Thanks for the answers so far.