samvermette/SVGeocoder — Issue #16: NSConcreteData objectAtIndex:]: unrecognized selector sent to instance
Author: cameroncooke
Created: 2012-01-27 12:43:55+00:00
State: open

I'm having a problem where if Google returns `ZERO_RESULTS` then this fires the delegate's `didFailWithError` and `respondsToSelector` methods, the latter causing the crash `NSConcreteData objectAtIndex:]: unrecognized selector sent to instance because`.

This is because `[response objectAtIndex:0]` fails to retrieve a non-existent placemark object.

**SVGeocoder.m**

``` if(error && [(NSObject*)self.delegate respondsToSelector:@selector(geocoder:didFailWithError:)])
[self.delegate geocoder:self didFailWithError:error];
if([(NSObject*)self.delegate respondsToSelector:@selector(geocoder:didFindPlacemark:)])
[self.delegate geocoder:self didFindPlacemark:[response objectAtIndex:0]];

else if([(NSObject*)self.delegate respondsToSelector:@selector(geocoder:didFindPlacemarks:)])
[self.delegate geocoder:self didFindPlacemarks:response];
```

I would expect the second **if** statement to be an **else if** so that `didFindPlacemark:` only gets called if Google returns a valid placemark.