Posted on

Bugs for Christmas

Today I start four days off for Christmas, so naturally I am back into Swift programming. I am working on the Clima app which finds the weather for a given city. I just started to implement CoreLocation but I came across a bug: didUpdateLocations was not getting called in my CLLocationManagerDelegate extension. I did some searching on Stack Overflow (which today I actually joined after being a lurker for years) and the solution was to call:

locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation])

instead of:

locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])

which was the default code dropped in when I code completed didUpdateLocations.

I also had an issue when looking up locations that had a space in their name, such as New York or Los Angeles. The urlString wasn’t converting these spaces to ‘%20’, so I changed it to:

let urlString = "\(weatherURL)&q=\(cityName)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!

Okay, the turkey is done and I am ready for Christmas lunch!