ios - nil object in NSDictionary -


i have nsdictionary read values in 2 different methods in code, in 1 of methods value of key retrieved correctly whereas in other method nil.

this method works:

-(void)drawdriver:(nsstring*)driverid withposition:(cllocationcoordinate2d)position withrotation:(float)bearing isavailable:(bool)isdriveravailable{      gmsmarker *drivermarker = [driverslist objectforkey:driverid];     if (drivermarker != nil) {         // work     } } 

and it's called other method:

- (void) socketio:(socketio *)socket didreceivemessage:(socketiopacket *)packet {     nsmutabledictionary *datos = (nsmutabledictionary*)packet.data;     nsdictionary *driverid = datos[@"from"];     nsstring *id = [driverid objectforkey:@"id"];      //gets other values      nslog(@"socket message: driverid: %@, position %f,%f, isavailable:%d", id, latitude, longitude, isdriveravailable);      //call first method     [self drawdriver:id withposition:position withrotation:bearing isavailable:isdriveravailable];  } 

and method doesn't work (returns nil drivermarker):

-(void)updatemapfortripwithdriver:(nsstring *)driverid {      gmsmarker *drivermarker = [driverslist objectforkey:driverid];     if (drivermarker != nil) {         //do work     } } 

and called here:

- (void)updatetripwithdata:(nsdictionary *)data {      //this nsdictionary comes notification     nsstring *newstatus = [[data objectforkey:@"aps"] objectforkey:@"alert"];      if ([newstatus isequaltostring:no_trip]) {      } else if ([newstatus isequaltostring:waiting_confirmation]) {      } else if ([newstatus isequaltostring:driver_on_the_way]) {          //get driverid , call other method         nsstring *driverid = [data objectforkey:@"driver_id"];         [self updatemapfortripwithdriver:driverid];     } } 

as can see both methods have exact same code retrieve object still different results. difference find when put breakpoints on methods , found:

on first method, although pass driverid nsstring, somehow it's read nsfcnumber , seems work because value no problems.

these values on first method

but on second method key read actual nsstring reason makes method return nil object exists on nsdictionary.

enter image description here

how can second method work , return right value?


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -