Implement The Singleton Pattern for Persistency managers Swift I am creating an iOS app and I want to implement Singleton Pattern.
I have created "Singleton" LibraryAPI to act as an entry point UserManager object to get data from web API. after that I used a facade Pattern "method" to call UserManager implementation.

final class LibraryAPI {

    static let shared  =  LibraryAPI()
    private let userManager  =  UsersManager()
    private let isOnline  =  false 

    private init(){

    }

    func getUsers() -&gt; [User] {
        return userManager.getUsers()
    }
}


my questions:


if I have another Manager Class like "album" class should I use the same LibraryAPI and it will become a monolithic class and how to avoid that? 
should I create a "Singleton" LibraryAPI class for each manager object like UserLibraryAPI and albumLibraryAPI?


Note: any references or articles are welcome :)
This seems to be an extremely common way of handling networking in iOS and Swift probably because it is very simple to reason about a single global singleton object for services.

I would recommend thinking carefully about using a singleton.

Why not just have a NetworkManager object that you initialize?

Even better why not separate out the services into a few logical classes? One service per class may get a bit arduous, but if you think critically you will likely be able to group services together appropriately. If you then find yourself with many Service objects, you can combine these objects with a facade pattern, that groups functionality when appropriate for a given View/ViewModel.

You will want to use classes, or structs with non static functions because when something isn't a singleton you can use dependency injection. Instead of accessing the static methods of your singleton you can inject a NetworkProvider object into the class in the constructor that uses it. This will make your code far more robust and testable. The injected object, if you created an appropriate Protocol, can be mocked.

Personally, I prefer something like Moya https://github.com/Moya/Moya/blob/master/docs/CommunityProjects.md. Its very swifty, logical, and well formatted. It also makes the relationships between services very clear. As your project gets larger, you will want to create multiple provider objects, but it provides a very concise way of writing your service layer. 

Summary - Use dependency injection and normal non static structs or classes. If you have multiple services, separate them out into a separate struct/class based on similarity or simply separate out one service into a single struct or class. A library like Moya can help to structure your code to make it more readable.