30 days with swift — Day 11 — It's all about location
Missed the last day, check here:
Location, location, location….
After we got the weather data we need to provide a way for the user to change his location because sometimes you want to know the rain probability in another place.
I choose to do that in a new screen called Settings, in this screen the user will be able to change the location and the notification time, and doing that we've practiced some of the navigation concepts.
For this particular screen I've choose the modal transition because the user change the settings and than he have to return to the main screen, this transition is used exactly in these situations, the other option is to use the navigation concept but isn't the case here.
Here's the final screen:
The other story we tackled today was the "update weather data" story, to do that I choose to change gears a little bit and I used the motion sensor. Now when te user shake the phone I run the getWeatherData function again and update the screen.
One of the most trickier part was to pass the new settings back to the main view controller, in objective-c, I usually create a delegate and call the delegate function in the "parent" view controller and than I do anything I want to do.
But I found a interesting solution in this link, the solution was creating an optional closure in the "child" controller and in the parent controller, before the segue, we point a function in the "parent" controller to the function in the "child" controller, that way I can pass the information back to the main controller. It's a little bit confusing but work pretty well.
That's it, today we accomplished a lot we finished all the stories of the first sprint using only 2 days.
Now the user are able to do the following:
As a users, I want to see the rain probability in the main screen
As a user, I want to set my current location to see the rain probability
As a user, I want to set a custom location to see the rain probability
As a user, I want to be able to refresh the information
Now we're going to jump to the second sprint and do more amazing things, swift is starting to look more and more familiar and the development process is faster each day.
If you're interested you can check the code at: https://github.com/akiokio/wheresMyUmbrella/tree/day-02 I tagged the day 01 and 02 if you want to see may daily progress.