Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes if types in address components is empty #7

Open
Armencho opened this issue Jun 21, 2015 · 1 comment
Open

Crashes if types in address components is empty #7

Armencho opened this issue Jun 21, 2015 · 1 comment

Comments

@Armencho
Copy link

In some cases Google Places API returns empty types array, for example Dallas/Fort Worth International Airport. In that case type = types.firstObject as NSString crashes
{
"long_name" = 2375;
"short_name" = 2375;
types = (
"street_number"
);
},
{
"long_name" = "Dallas/Fort Worth International Airport";
"short_name" = "Dallas/Fort Worth International Airport";
types = (
);
},
{
"long_name" = "International Parkway";
"short_name" = "International Pkwy";
types = (
route
);
},
{
"long_name" = Dallas;
"short_name" = Dallas;
types = (
locality,
political
);
},
{
"long_name" = "Tarrant County";
"short_name" = "Tarrant County";
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = Texas;
"short_name" = TX;
types = (
"administrative_area_level_1",
political
);
},
{
"long_name" = "United States";
"short_name" = US;
types = (
country,
political
);
},
{
"long_name" = 75261;
"short_name" = 75261;
types = (
"postal_code"
);
}
)

@kunj369
Copy link

kunj369 commented Dec 6, 2016

if let dictData = obj as? NSDictionary {
let objDict:NSDictionary = dictData
if let array = objDict.objectForKey("types") as? NSArray {
let types:NSArray = array
if let type = types.firstObject as? NSString{
return type.isEqualToString(component as String)
}else{
return false
}
}else{
return false
}
}else{
return false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants