I have an app written using MVVM and RxSwift. For navigation I'm using coordinator

What is the best way to store user's credentials and pass them to Network Layer.

I don't want to sore them in DB or keychain. I want them to persist in memory while app is running. Also wanted to omit having singleton with Credentials.

  • 1
    Sharing your research helps everyone. Tell us what you've tried and why it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask
    – gnat
    Commented Sep 12, 2021 at 20:35
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Sep 12, 2021 at 23:15
  • 1
    Why wouldn’t you want to use the keychain? It’s there to keep confidential data confidential. And why don’t you want to use a singleton?
    – gnasher729
    Commented Sep 13, 2021 at 6:43
  • 1
    You can design your network code without having a persistently stored access token. In fact, this is even suggested for better security. You would need to store a refresh token persistently, though. Having some global but also volatile state which keeps the access token makes sense. You may also try to pass this same state as parameters to every function involved, thus avoiding a global. MVVM and RxSwift has nothing to do with this design. Commented Sep 20, 2021 at 11:17

1 Answer 1


There are three ways to store the credentials... Put them in storage (either secure or otherwise) to retrieve them when needed, put them in some sort of globally accessible memory location (this could be an object that is itself globally accessible, doesn't expose the credentials but uses them,) or pass them to every object that needs them.

You have mentioned that you don't want to do either of the first two. That means you will be passing the credentials around to every object that needs them.

  • Thanks! Actually I've reconsidered my plans and I opted for putting them in globally accessible memory location
    – Roma
    Commented Sep 20, 2021 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.