ios - index 0 beyond bounds for empty array' libc++abi.dylib: terminate called throwing an exception -
i new xcode please guide me right error, code is,
//set our mapview [mapviewc setregion:myregion animated:no]; cllocation *somelocation=[[cllocation alloc]initwithlatitude:latitude longitude:longitude]; clgeocoder *geocoder = [[clgeocoder alloc] init]; [geocoder reversegeocodelocation:somelocation completionhandler:^(nsarray *placemarks, nserror *error) { nsdictionary *dictionary = [[placemarks objectatindex:0] addressdictionary]; addressoutlet=[dictionary valueforkey:@"street"]; city=[dictionary valueforkey:@"city"]; state=[dictionary valueforkey:@"state"]; if (addressoutlet!=null&&city!=null) { nsstring *subtitle=[nsstring stringwithformat:@"%@,%@,%@",addressoutlet,city,state]; cell.detailtextlabel.text=subtitle; } else if (addressoutlet==null&&city!=null) { nsstring *subtitle=[nsstring stringwithformat:@"%@,%@,",city,state]; cell.detailtextlabel.text=subtitle; } else if (addressoutlet!=null&&city==null) { nsstring *subtitle=[nsstring stringwithformat:@"%@,%@,",addressoutlet,state]; cell.detailtextlabel.text=subtitle; } else if(addressoutlet==null&&city==null) { nsstring *subtitle=[nsstring stringwithformat:@"%@",state]; cell.detailtextlabel.text=subtitle; } }];
thanks in advance.
ok array can empty, in case next statement cause exception:
nsdictionary *dictionary = [[placemarks objectatindex:0] addressdictionary]; // ^
so guard against it, like:
if ([placemarks count] > 0) { nsdictionary *dictionary = [[placemarks objectatindex:0] addressdictionary]; .... }
i haven't read api docs completion handler, can probably test if error
non-nil
, deed accordingly (i.e. if error != nil
respond error, else process placemarks
array).
ios objective-c indexoutofboundsexception
No comments:
Post a Comment