Chapter    6

The Singleton Pattern

I describe the singleton pattern in this chapter, which ensures that only one object of a given type exists in the application. This is one of the most commonly used design patterns because it solves problems that arise often, either because you need an object to represent a real-world resource or because you want to ensure that all activity of a certain kind—such as logging—is handled in a consistent way. Table 6-1 puts the singleton pattern in context.

Table 6-1. Putting the Singleton Pattern into Context

Question

Answer

What is it?

The singleton pattern ensures that only one object of a given type exists in the application.

What are the benefits?

The singleton pattern can be used to manage objects that represent ...

Get Pro Design Patterns in Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.