Shape Shape point chapter-list Group Group Group Shape Copy 12 Shape Shape Copy 3 Shape Shape dropdown editor editor Combined Shape grid Shape Copy 4 Shape Copy 7 Shape language language Shape megaphone paperback Shape platform noun_419259-2 copy play-icon BS-Question-Rounded-Circle quotes noun_610406 stacked-books-1 stacked-books-2 Group Group Group Group Group

Design Patterns by Tutorials

$59.99 4.6/5 9 reviews · Write a Review
  • Platform iOS 13
  • Language Swift 5
  • Editor Xcode 11

Learn iOS design patterns with Swift!

This book starts with basic patterns like MVC, Delegate and Strategy, and then moves into more advanced patterns such as the Factory, Prototype, Multicast Delegate, Flyweight, Command, and more.

Design patterns are incredibly useful, no matter which language or platform you develop for. Every developer should know how to implement them, and most importantly, when to apply them. That's what you're going to learn in this book!

Developer Guide


For Beginner Developers

Learn design patterns with Swift!

Design patterns are incredibly useful, no matter what language or platform you develop for. Using the right pattern for the right job can save you time, create less maintenance work for your team and ultimately let you create more great things with less effort. Every developer should absolutely know about design patterns, and how and when to apply them. That's what you're going to learn in this book!

Move from the basic building blocks of patterns such as MVC, Delegate and Strategy, into more advanced patterns such as the Factory, Prototype and Multicast Delegate pattern, and finish off with some less-common but still incredibly useful patterns including Flyweight, Command and Chain of Responsibility.

And not only does Design Patterns by Tutorials cover each pattern in theory, but you’ll also work to incorporate each pattern in a real-world app that’s included with each chapter. Learn by doing, in the step-by-step fashion you’ve come to expect in the other books in our by Tutorials series.

Table of Contents

Section I: Hello, Design Patterns!


What are Design Patterns?

Design patterns aren’t concrete implementations, but rather, serve as starting points for writing code. They describe generic solutions to problems that many experienced developers have encountered many times before. What does this mean exactly...? Learn this and more in this chapter.


How to Read a Class Diagram

You may have heard of Unified Modeling Language, which is a standard language for creating class diagrams, architectural drawings and other system illustrations. A complete discussion of UML is beyond the scope of this book, but you won't need to understand a lot of UML in your day-to-day iOS development. Instead, you'll learn a subset of UML in this chapter that's useful for creating class diagrams and describing design patterns.

Section II: Fundamental Design Patterns


Model-View-Controller Pattern

The model-view-controller (MVC) pattern separates objects into three distinct types: models, views and controllers! MVC is very common in iOS programming, because it's the design pattern that Apple chose to adopt heavily in UIKit. In this chapter you’ll implement the MVC pattern as you start to build out the first app in this book: RabbleWabble.


Delegation Pattern

The delegation pattern enables an object to use another “helper” object to provide data or perform a task rather than the task itself. By relying on a delegate protocol instead of a concrete object, the implementation is much more flexible: any object that implements the protocol can be used as the delegate! You'll continue the RabbleWabble app from the previous chapter, and add a menu controller to select the group of questions.


Strategy Pattern

The strategy pattern defines a family of interchangeable objects that can be set or switched at runtime: the object using a strategy, the strategy protocol, and the set of strategies. You continue to build out Rabble Wabble and learn how these three components work together in the strategy pattern.


Singleton Pattern

The singleton pattern restricts a class to only one instance. Every reference to the class refers to the same underlying instance. It is extremely common in iOS app development, because Apple makes extensive use of it.


Memento Pattern

The memento pattern allows an object to be saved and restored. you can use this pattern to implement a save game system, where the originator is the game state (such as level, health, number of lives, etc), the memento is saved data, and the caretaker is the gaming system. You can also persist an array of mementos, representing a stack of previous states. You can use this to implement features such as undo/redo stacks in IDEs or graphics software.


Observer Pattern

The observer pattern lets one object observe changes on another object. You’ll learn two different ways to implement the observer pattern in this chapter: using key value observation (KVO), and using an `Observable` wrapper.


Builder Pattern

The builder pattern allows the creation of complex objects step-by-step, instead of all at once, via an initializer. For example, you can use this pattern to implement a “hamburger builder”. The product could be a“`hamburger” model, which has inputs such as meat selection, toppings and sauces. The director could be an “employee” object, which knows how to build hamburgers, or it could be a view controller that accepts inputs from the user.

Section III: Intermediate Design Patterns


Model-View-ViewModel Pattern

Use this pattern when you need to transform models into another representation for a view. This pattern compliments MVC especially well. You’ll embark on a new project — CoffeeQuest — to help you find the best coffee shops around.


Factory Pattern

The factory pattern provides a way to create objects without exposing creation logic. Technically, there are multiple "flavors" of this pattern, including a simple factory, abstract factory and others. However, each of these share a common goal: to isolate object creation logic within its own construct.


Adapter Pattern

Classes, modules, and functions can’t always be modified, especially if they’re from a third-party library. Sometimes you have to adapt instead! You can create an adapter either by extending an existing class, or creating a new adapter class. This chapter will show you how to do both.


Iterator Pattern

The Iterator Pattern provides a standard way to loop through a collection. Use the iterator pattern when you have a class or struct that holds a group of ordered objects, and you want to make it iterable using a “for in” loop.


Prototype Pattern

Methods are merely functions that reside in a class. In this chapter, you’ll take a closer look at methods and see how to add methods onto classes that were created by someone else. You’ll also start in on a new project with this chapter: a drawing app named MirrorPad.


State Pattern

The state pattern is a behavioral pattern that allows an object to change its behavior at runtime. It does so by changing its current state. "State" here means the set of data that describes how a given object should behave at a given time.


Multicast Delegate Pattern

The multicast delegate pattern is a behavioral pattern that’s a variation on the delegate pattern. It allows you to create one-to-many delegate relationships, instead of one-to-one relationships in a simple delegate. Use this pattern to create one-to-many delegate relationships.


Facade Pattern

The facade pattern is a structural pattern that provides a simple interface to a complex system. Use this pattern whenever you have a system made up of multiple components and want to provide a simple way for users to perform complex tasks.

Section IV: Advanced Design Patterns


Flyweight Pattern

This creational design pattern minimizes memory usage and processing. It also provides objects that all share the same underlying data, thus saving memory. Learn about flyweight objects and static methods to return them.


Mediator Pattern

This is a behavioral design pattern that encapsulates how objects, called colleagues for this pattern, communicate with one another. This pattern is useful to separate interactions between colleagues into an object, the mediator. Learn how to use it when you need one or more colleagues to act upon events initiated by another colleague.


Composite Pattern

This is a structural pattern that groups a set of objects into a tree so that they may be manipulated as though they were one object. If your app's class hierarchy forms a branching pattern, trying to create two types of classes for branches and nodes can make it difficult for those classes to communicate. Learn how to reduce complexity and solve this problem with this pattern.


Command Pattern

This is a behavioral pattern that encapsulates information to perform an action into a command object. Learn how you can model the concept of executing an action and to use this pattern whenever you want to create actions that can be executed on different receivers.


Chain of Responsibility Pattern

This is a behavioral design pattern that allows an event to be processed by one of many handlers. See how to use this pattern whenever you have a group of related objects that handle similar events but vary based on event type, attributes or something else related to the event.


Coordinator Pattern

The coordinator pattern is a structural design pattern for organizing flow logic between view controllers. This pattern can be adopted for only part of an app, or it can be used as an “architectural pattern” to define the structure of an entire app. You’ll see both of these at work in this chapter.

Meet the team

Customer reviews

Design Patterns by Tutorials

The book all iOS and macOS developers have all been waiting for: "Design Patterns by Tutorials” is the best of the wisdom of that gang of four written in Swift. Need a singleton that's ready to try in a playground, along with clear guidance about how to use it and not misuse it? This is your essential guide.

Mark Powell

Often times we talk to a duck to determine when we should be using or avoid an iOS design pattern. But why talk to a duck when you can find all your answers in the Design Patterns by Tutorial book? It also comes with great examples.

Jen Chang

The book is laid out great and the content is top notch. You can go straight to the table of contents to find the design pattern of interest or read the book from cover to cover. Hands on tutorials make all the difference and this book has them. I highly recommend this book!

Mike Finney

Average Rating

4.6 /5

Leave a review for this product

9 reviews

Design Patterns by Tutorials

Learn iOS design patterns with Swift!

This book starts with basic patterns like MVC, Delegate and Strategy, and then moves into more advanced patterns such as the Factory, Prototype, Multicast Delegate, Flyweight, Command, and more.

Design patterns are incredibly useful, no matter which language or platform you develop for. Every developer should know how to implement them, and most importantly, when to apply them. That's what you're going to learn in this book!