I am trying to get the weather for a city using Openweathermap API using this code:
struct WeatherManager { let weatherURL = "https://api.openweathermap.org/data/2.5/weather?appid=XXXXXXXX&units=imperial"
var delegate: WeatherManagerDelegate?
func fetchWeather(cityName: String) {
let urlString = "\(weatherURL)&q=\(cityName)"
performRequest(with: urlString)
}
My issue is that Openweathermap API is not very flexible because when you search a city with no spaces like Paris it works fine but if you need to search a city like San Francisco that has a space it won't work unless its typed as San+Francisco.
Where and what type of code can I create that if a space is entered into the search field that it is changed to + and able to fetchWeather and if no spaces are entered it can still use the fetcheWeather.
Super noob so guidance is helpful, thanks in advance!
I want the code to be flexible to take search field text and if there are spaces insert + when fetching weather