NSArray objectAtIndex index 0 beyond bounds for empty array

孤人 提交于 2019-12-06 01:01:29

The code makes an assumption that response array always has at least one element. This breaks when the array is empty, so you need to add code to check for it:

NSArray *response = [responseObject objectForKey:@"results"];
if (response.count == 0) {
    // Continue loading more data:
    [self loadLatLong];
    return;
}
NSDictionary *geo = [response[0] objectForKey:@"geometry"];

It is crashed because the response don't have any object. You should check it before calling response[0]. Something like this if ([response count] == 0) return;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!