ios - Function Does Not Recognize Array Values -


i tried create array via parsing .csv file run through function.

//array  nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"499csv" oftype:@"csv"]; nsstring *csvstring = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:nil];  nsarray *locations = [csvstring componentsseparatedbycharactersinset:[nscharacterset newlinecharacterset]];  nsmutablearray *secondarray = [nsmutablearray array]; (nsstring * location in locations) {  nsarray *components = [location componentsseparatedbystring:@","];  double latitude   = [components[0] doublevalue]; double longitude  = [components[1] doublevalue]; nsstring *station =  components[2];  nsdictionary *dict = @{@"klatitude": @(latitude),                        @"klongitude": @(longitude),                        @"kstation": station};  [secondarray addobject:dict];  }  //comes out  secondarray = (     {     klatitude = "41.656467";     klongitude = "-81.277963";     kstation = 27200; },     {     klatitude = "41.657118";     klongitude = "-81.276545";     kstation = 27650; },     {     klatitude = "41.658493";     klongitude = "-81.27354200000001";     kstation = 28632; }...   //function  nsarray *orderedplaces = [locationsarray sortedarrayusingcomparator:^(id a,id b) {  nsdictionary *dicta; nsdictionary *dictb; cllocation *loca; cllocation *locb;  dicta = (nsdictionary *)a; dictb = (nsdictionary *)b; loca = [[cllocation alloc] initwithlatitude:[[dicta objectforkey:klatitude] doublevalue]longitude:[[dicta objectforkey:klongitude] doublevalue]]; locb = [[cllocation alloc]         initwithlatitude:[[dictb objectforkey:klatitude] doublevalue]         longitude:[[dictb objectforkey:klongitude] doublevalue]]; 

problem function not recognize array values. guess has how define values. specifically, call klatitude , klongitude.

can identify why function not read secondarray values firstarray values? , how can fix it? in advance time.

you have defined dictionary keys:

#define kstation @"station" #define klatitude @"latitude" #define klongitude @"longitude" 

try:

nsdictionary *dict = @{klatitude : @(latitude),                        klongitude: @(longitude),                        kstation  : station}; 

you use them in first array creation, not in second.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -