I'm working on an App that returns some JSON data that the user is searching for in a tableView. Sometimes there is an empty key that is returned and it seems to be crashing my app if a selection is choosin. I've looked up other solutions, but its still crashing regardless of how I set up my "if" check.
This first one is weird, it works but in the text view where the data is displayed "{}" is displayed instead of "Not Available..." Why?
if ([gameDetails objectForKey:@"description"] !=nil) {
gameDescription.text = [NSString stringWithFormat:@"%@", [gameDetails objectForKey:@"description"]];
}
else
{
gameDescription.text = [NSString stringWithFormat:@"Not Available..."];
}
The next one crashes regardless of how I set it up.
if ([gameDetails objectForKey:@"box_front"] != nil) {
NSURL *coverImage = [NSURL URLWithString:[gameDetails objectForKey:@"box_front"]];
NSData *imageLink = [NSData dataWithContentsOfURL:coverImage];
coverArt.image = [UIImage imageWithData:imageLink];
}
else
{
NSLog(@"No Photo");
}
Can someone tell me why these are causing my app to keep crashing? Let me know if I need more information.
descriptionkey. In the 2nd case you don't mention the error but most likely you are getting anNSNullobject.NSDictionary descriptionon an empty dictionary will be{}. BTW - when you wish to reply to a specific person, put the@symbol before their username.