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.
but on second method key read actual nsstring reason makes method return nil object exists on nsdictionary.
how can second method work , return right value?


Comments
Post a Comment