Building a Weather Application From Scratch


In Mastering MVVM With Swift, we refactor a weather application, Cloudy, built with MVC to use MVVM instead. One of the most common questions I receive is how to build Cloudy from scratch. This series is an answer to that question. We build a weather application that is inspired by Cloudy. The application is aptly named Rainstorm.

The goal of this series isn't to teach you Swift and Cocoa development. This series assumes that you have a basic understanding of the Swift language and the iOS SDK. The goal is to show you how to build a production application from start to finish. I show you how to set up the project, discuss the decisions I make along the way, and highlight key patterns that power the project.

Before we fire up Xcode and create the project, I'd like to give you a glimpse of what you can expect from this series. As I mentioned earlier, the project is powered by the Model-View-ViewModel pattern. It's a pattern I use in every project. It's easy to adopt and implement. I consider the Model-View-ViewModel pattern an improved version of the Model-View-Controller pattern.

The project also adopts view controller containment, another pattern I use in every project I work on. Navigation controllers, tab bar controllers, and split view controllers are UIKit components that take advantage of view controller containment.

Testing has become an important aspect in the Swift and Cocoa communities and we explore how to leverage unit tests to build a stable and robust application. Unit testing becomes much easier if you embrace dependency injection. If you're new to dependency injection, then this series shows you how easy it is to adopt. Dependency injection is also a potent solution for curing projects from singletonitis.

Most applications rely on the network to fetch data from a remote backend. The weather application we're about to build is no different. We fetch weather data from the Dark Sky API, an easy to use weather service. The requests the application performs aren't complex and we won't be relying on a third party networking library. The URLSession API is more than sufficient.

Parsing the data we receive from the Dark Sky API isn't complicated thanks to the Codable protocol. Working with JSON used to be tedious and clunky. That's no longer true.

There's much more you learn along the way, including working with storyboards and storyboard references, protocol-oriented programming, namespacing with enumerations, the power of value types, asynchronous programming, and debugging applications with Xcode.

This series also illustrates that you don't need rely on third party libraries to build an application. It's true that there are countless outstanding third party libraries available, but a third party library shouldn't be your first or default choice. It's important that you first become familiar with the native APIs before you consider a third party solution.

In the next episode, we fire up Xcode and set up the project. There's more to it thank you may think.

Next Episode "Setting Up the Project"