Daily iOS
Architecture

Scope of a singleton

In a travel app, a global SessionManager.shared holds auth, cache, analytics, and experiment values all at once, and that makes testing hard. How would you decide what can stay a singleton and what has to move to initializer injection?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Only what truly must be one per process and never needs swapping in tests, like a logger or app bundle info, stays a singleton; anything that needs a different value per test, like login state or experiment values, is defined as a protocol and injected through init.

Share a question