Home > DeveloperSection > Interviews > How can we achieve singleton pattern in iOS?

Posted on    August-04-2015 11:12 PM

 iPhone iPhone  Ios  Objective C 
 1 Answer(s)
  489  View(s)
Rate this:

Glen Martin
Glen Martin

Total Post:4

Posted on    August-04-2015 11:12 PM

The Singleton design pattern ensures a class only has one instance, and provides a global point of access to it. The class keeps track of its sole instance and ensures that no other instance can be created. Singleton classes are appropriate for situations where it makes sense for a single object to provide access to a global resource. Several Cocoa framework classes are singletons. They include NSFileManager, NSWorkspace, NSApplication, and, in UIKit, UIApplication. A process is limited to one instance of these classes. When a client asks the class for an instance, it gets a shared instance, which is lazily created upon the first request.

Modified On Aug-04-2015 11:13:25 PM

Don't want to miss updates? Please click the below button!

Follow MindStick