Redeem Now
Read More
Read now

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!

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again