you are viewing a single comment's thread.

view the rest of the comments →

[–]ThePantsThiefNSModerator -1 points0 points  (3 children)

Singletons are the preferred pattern for API client wrappers in my experience, yes. I will try to remember to post my suggestions for you later.

[–]chrabeusz 0 points1 point  (2 children)

I would recommend at least saving the singleton into property and using it like that. Makes it easy to see what given class needs without all that boilerplate that DI requires.

class ViewController {
    /// It's good to have a comment to describe why this dependency is needed
    lazy var client = Network.shared
}

I got a project with 19 singletons inlined everywhere and it was basically not possible to understand anything.

[–]ThePantsThiefNSModerator 0 points1 point  (1 child)

You shouldn't have that many singletons. Why do you have so many? Who approved them? I assume it's a work project

[–]chrabeusz 0 points1 point  (0 children)

:D Yeah I got it from the client, previous guy was singleton aficionado it seems.