Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Guard against nil in NSDictionary #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ios/RNGeocoder/RNGeocoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,19 @@ - (NSArray *)placemarksToDictionary:(NSArray *)placemarks {
for (int i = 0; i < placemarks.count; i++) {
CLPlacemark* placemark = [placemarks objectAtIndex:i];

NSString* name = [NSNull null];
NSObject *name = nil;

if (![placemark.name isEqualToString:placemark.locality] &&
![placemark.name isEqualToString:placemark.thoroughfare] &&
![placemark.name isEqualToString:placemark.subThoroughfare])
{

name = placemark.name;
}

NSArray *lines = placemark.addressDictionary[@"FormattedAddressLines"];

NSDictionary *result = @{
@"feature": name,
@"feature": name ?: NSNull.null,
@"position": @{
@"lat": [NSNumber numberWithDouble:placemark.location.coordinate.latitude],
@"lng": [NSNumber numberWithDouble:placemark.location.coordinate.longitude],
Expand Down