A few months ago Paul Hudson asked me if I would be interested in contributing to a new book. The idea of the book was this: many authors, each writing a chapter about Swift, with all proceeds going to charity. I quickly accepted and began writing.

This week, the book is a reality! The book is entitled Swift for Good and includes content from twenty different authors. All proceeds of the book benefit Black Girls Code, a charity devoted to proving to the world that girls of every color have the skills to become software engineers.

Swift for Good

My chapter covers writing a networking stack in Swift that uses TheMovieDB’s API as an example. In the chapter, we build out everything we need to get a robust, extensible networking layer in our project that allows us to write our requests like this:

MovieDB.api.send(request: .popularMovies({ result in
     switch result {
         case .success(let page):
             self.movies = page.results

         case .failure(let error):
             print("Error: \(error)")
     }
 }))

The chapter also goes into how we might leverage Request Adapters to provide things like authorization headers to every request or logging to get some insight into how our network requests are working. Along the way we leverage a number of Swift’s strengths such as Codable models, protocol extensions, enums, auto closures, and inline types.

I’m quite happy with how my chapter turned out. There’s also a load of excellent material from the other amazing authors in the book.

Thanks to Paul Hudson for putting this project (and the book, literally) together! Also thanks to the other 19 authors for donating their time and expertise to build a book for a good cause. I’m proud to have been a part of it!

You can buy the book here:  https://www.swiftforgood.com

I do hope you check it out!