Open Armencho opened 9 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 }
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" ); } )