ios - Exception thrown if string is null -


i getting exception if string null:

terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsnull length]: unrecognized selector sent instance 

this 1 of objects of dictionary,that contains null string:

{     cabdriver = "<null>";     code = sv1000000079;     date = "2015-03-15";     destiny = "";     email = "jose@gmail.com";     origin = vxd; } 

and code exception thrown:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     historialcelltableviewcell *cell = (historialcelltableviewcell *)[tableview dequeuereusablecellwithidentifier:@"cell"];      nsstring *origin = [[historialservicios objectatindex:indexpath.row] valueforkey:@"origin"];     if (origin.length ==0){         cell.origen_label.text = @"-";     } else {         cell.origen_label.text = origin;     }      nsstring *destiny = [[historialservicios objectatindex:indexpath.row] valueforkey:@"destiny"];     if (destiny.length ==0){         cell.destiny_label.text = @"-";     } else {          cell.destiny_label.text = destiny;     }       nsstring *cabdriver = [[historialservicios objectatindex:indexpath.row] valueforkey:@"cabdriver"];     if (cabdriver.length ==0){         cell.conductor_label.text = @"-";     } else {         cell.conductor_label.text = cabdriver;     }      nsstring *date = [[historialservicios objectatindex:indexpath.row] valueforkey:@"date"];      cell.fecha_label.text = date;     return cell; } 

i have tried other ways check if string null, have been searching , should way check it.

please tell me wrong in code?

when processing data returned server should prepared of values null. use following 2 methods - 1 check string, other check number:

- (nsstring *)stringvalueofdictionaryobject:(id)dictionaryobject {     if (dictionaryobject == [nsnull null]) {         return @"";     }     else {         return (nsstring *)dictionaryobject;     } }  - (nsnumber *)numericvalueofdictionaryobject:(id)dictionaryobject {     if (dictionaryobject == [nsnull null]) {         return nil;     }     else {         return (nsnumber *)dictionaryobject;     } } 

in case of cab driver, following:

nsstring *cabdriver = [self stringvalueofdictionaryobject:(id)[[historialservicios objectatindex:indexpath.row] valueforkey:@"cabdriver"]]; 

note if cab driver value null in json file, routine above return empty string (@""). change @"-" either in routine or after getting cabdriver nsstring value.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -