jimmyjose-dev / LocationManager

CLLocationManager wrapper in Swift, performs location update, geocoding and reverse geocoding using Apple and Google service
MIT License
713 stars 119 forks source link

Crashes if types in address components is empty #7

Open Armencho opened 9 years ago

Armencho commented 9 years ago

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 commented 8 years ago

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 }