iphone - How to check if string in nsdictionary is null -
i'm working on twitter app , trying implement tweet location. want display name of country , display on map if tweet has location. whatever i've tried displays country of first tweet or if it's null app crashes. don't understand i'm doing wrong. can help? thank you! here's code:
// location (nsdictionary *dic in self.datasource) { nsstring *str = [dic valueforkeypath:@"place.name"]; if(str) { cell.button.hidden = no; cell.location.text = [dic valueforkeypath:@"place.full_name"]; self.coordinates = [dic valueforkeypath:@"geo.coordinates"]; break; } else { cell.button.hidden = yes; cell.location.hidden = yes; break; } }
and nslog output:
2013-08-20 00:04:42.269 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.269 twitterapplication[10011:c07] downtown 2013-08-20 00:04:42.269 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.270 twitterapplication[10011:c07] moscow 2013-08-20 00:04:42.270 twitterapplication[10011:c07] Брянск 2013-08-20 00:04:42.270 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.271 twitterapplication[10011:c07] Брянск 2013-08-20 00:04:42.271 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.271 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.272 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.272 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.272 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.273 twitterapplication[10011:c07] <null> 2013-08-20 00:04:42.273 twitterapplication[10011:c07] <null>
why check value @"place.name" , use @"place.full_name"? maybe problem.
and think have check @"geo.coordinates" value before using it.
try change if statement if(str && str.lengh)
and change nsstring *str = [dic valueforkeypath:@"place.name"];
nsstring *str = [[dic valueforkeypath:@"place.name"] lastobject];
because valueforkeypath returns array.
Comments
Post a Comment