Search code examples
swiftopenweathermap

Open Weather Map does recognize city name when textField contains two substring


if city name is "La Paz", Open Weather Map will not return JSON Data but it will return it if the user enter a city with one substring e.g. Richmond.

let urlString = "\(weatherURL)&q=\(cityName)"

how can I fix this? Thank you in advance for your help.


Solution

  • Although you question is not fully clear, I assume the issue has to do with the spacing in the textfield. You could try it by using the function addingPercentEncoding(withAllowedCharacters:). This will make the string more URL safe.

    Otherwise I'd suggest checking the documentation for Weather Map and see if it requires data differently.