Swift — SharedInstance

SharedInstance is a Singleton in Objective C. Singleton is one of the most commonly used design patterns in software engineering. Singleton is an object which is instantiated exactly once. Only one copy of this object exists and the state is shared and reachable by any other object.

Shared Instance is a process by which you can access the same instance of object of the class anywhere in project. It returns the same object each time a method is called so that the properties stored in the instance can be used anywhere in the application.

The

The shared instance can be implemented using static variable initialized only once:

Example,

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.