Development step 6: Debugging the error

In this step, my main focus is Fixing the bug when I was in app searching for some specific city, the app neither responded nor showed the same stats as the previous city

I had recognized this weird behaviour a few steps back but blamed it on my inconsistent wifi signal at home. But after several test at different places, I knew that was not the case and I had to make it right.

1.The error

I found out out that the behavior when I input “Enschede" to the search box, nothing happened, instead it showed the view controller's debug windows like this:

2. Approach to solve the errors

I also try some other cities like Paris, London,… it worked totally fine. Then after a while scratching my head and google for the Thread 1: EXC_ BAD_ INSTRUCTION as in debug windows, nothing seemed to be clear to me. I then decided to test it several times by looking to the city that gave me error, including New York, Las Vegas, Los Angeles, Enschede sometimes,… I also grouped the city without the error (Paris, London, Amsterdam, Singapore,…) and started opening the app, then searched for “error-group" cities. The result was that the temperature of “error-group" cities always stayed the same as previous normal-group city. After some time thinking, I decided to take a look at the JSON file that included the temperature of “error-group" cities, comparing them to normal-group cities.

Weather in Celsius of error-group city

3. References

Here I saw that the temperature was not an integer number. A lookup on google and stack exchange gave me the answer:

4. Solution

Finally, found out that I needed to round the number Apixu data output, and convert them to integer so that the temperature would show up in clear form.

if let temp = current["temp_c"] as? Float { = Int(temp.rounded())

It also explain that for some cities in the US, they used the Fahrenheit scales, so when converted to Celsius, it always in Float form so Most of city in US I always came to this errors!

5. What I have learned…

Well, taking some time off, get out to the park and go back to work again with my source code (with my laptop always open xcode) simply works ;).

I also find out that stackoverflow was areally helpful community, being my bug killer hero several times.