7.
Introducing Dog Patch
Written by Joshua Greene
You’ve learned the basics of TDD, and you should be starting to feel comfortable with it. However, you haven’t learned how to do TDD for a very critical part of most apps: networking!
Over the next several chapters, you’ll learn the ins-and-outs of writing networking code in a test-driven fashion. The goal of this chapter is to introduce you to this section’s sample project and highlight what work remains to be completed.
Getting started
You’ll complete a puppy-adoption app called Dog Patch throughout this section. This app connects dog lovers with kind, professional breeders to find the puppy of their dreams.
Let’s go over what needs to be done to make this possible.
Networking client
In Chapter 8, you’ll learn how to start TDD for RESTful networking. You’ll first explore the starter project and find that ListingsViewController always shows an error:
This is because the app isn’t actually doing any networking yet! You’ll create a networking client and make a GET request to fetch Dog models from a remote server as the first steps to fix this.
Using a networking client
In chapter 9, you’ll follow TDD to use your networking client in a view controller. Ultimately, your app will be able to display networking results to the user, except for images:
Specifically, you’ll update ListingsViewController to use DogPatchClient, the networking client that you created in the last chapter.
Image client
In chapter 10, you’ll create an image client and update ListingsViewController to use it to display images:
Understanding Dog Patch’s architecture
You’ll use Model-View-Controller-Networking (MVC-N) for this app’s architecture. If you’ve done any work in iOS before, you’re very likely familiar with the Model-View-Controller (MVC) architecture, wherein you separate objects into three types. These are aptly named models, views and controllers, of course.
MVC-N is a spin-off architecture of MVC. Instead of just three types, however, it separates out a fourth type for networking.
Especially for networking-heavy apps like Dog Patch, it makes sense to separate networking into its own type. If you didn’t do this, where would the networking code go, after all? In pure MVC-architecture apps, developers tend to lump networking into each view controller.
The problem here is that a lot of networking code is interrelated. For example, URL and content serialization, authentication headers and more require exactly the same logic. If networking code is directly in each view controller, you quickly wind up with a lot of duplication. This quickly becomes an unmanageable mess as a result.
Fortunately, MVC-N allows you to avoid this issue altogether by putting your networking code into a networking client. This client is then passed into whatever view controllers need it, and this effectively eliminates the duplication across view controllers.
It’s OK if you haven’t heard of MVC-N before. You’ll learn all about it over the course of the next few chapters!
Where to go from here?
This chapter introduced Dog Patch and what you’ll be doing over the next few chapters. Continue onto the next chapter to dive into the code!