Chapter 7. Singleton

In mathematics and logic, a singleton is defined as "a set that contains exactly one element." So no matter how big a pouch is, every time you are trying to get a marble out of it you will get only the same one. Under what situations do we need a singleton in software? Think about resources that can be shared only in a system and no copies of them can be made available to others. For example, the GPS device is the sole hardware on the iPhone that provides coordinates of the device in real time. The CLLocationManager class of the CoreLocation framework provides a single access point to any services that the GPS device offers. Some people may think, if I can make a copy of CLLocationManager, then can I get an extra set of GPS ...

Get Pro Objective-C Design Patterns for iOS 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.