Use of Singleton Pattern in Swift


What is Singleton?

Where can we use?

Almost every application uses a network calls its good practice implement network calls in single class from where you can fetch data and treat the way you want to use them. Most of us create an object of that class for every time you need to call a network and every time you create an object of a class a new instance of that class created that is directly proportional to the memory of your application to avoid this problem you can use Singleton Pattern.

Implementation of Singleton:-

Why final?

Apply this final to a class or to a property, method, or subscript member of a class. It’s applied to a class to indicate that the class can’t be subclassed.

Private init because no other class will initialize this class.

Create a return class type function which will return your singleton object:-

How to Use:-

From sharedObject object, you can call any function NetworkManager.


I hope from this you can implement Singleton. Thanks for tuning in once again!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.


Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.

Stathis Plakidas

Stathis Plakidas

Talk to Sales


Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home