O'Reilly logo

Cocoa Design Patterns by Donald A. Yacktman, Erik M. Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13. Singleton

The Singleton pattern is used when there must be exactly one instance of a class, and it must be easily accessible to other objects in an application. Usually, the Cocoa documentation uses the term shared instance when the Singleton pattern is in use.

In Cocoa, one example of a Singleton is the NSApplication class. It maintains the application’s connection to the window server for drawing and receiving events. Cocoa optionally takes advantage of Dynamic Creation and Bundles to substitute an instance of your own class for the default NSApplication instance.

Motivation

Define conventions for the creation of and access to an instance in cases where only one instance of a class should be created. Often singletons represent physical ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required