Learn Courses My Dashboard

Multiple Async Calls

I have an app that retrieves data from a database multiple times.
The more data there is in the database, the longer it takes for my app to load once the user initially logs in and goes to different screens.
I’m thinking I need to make the methods that get data from the database asynchronous, but I’m having a hard time understanding how to do it.


Here is an example. I have a getUserData method that calls other methods that access my firebase database.

I also have this init method in my View Model that calls methods that access the same database, like getCompanyCodes and getUserData.

I want the UI to be smooth and not freeze as the user moves between screens and logs in.

Can you paste your code in as text, rather than providing a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key). You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.