1

I am writing an iOS application in XCode. The data loaded for the multitudes of viewcontrollers is generally loaded from the DB upon the viewDidLoad() or viewDidAppear() for that particular VC, or it it is passed from one VC to another upon IBAction button clicks.

I am wondering if there is a better/more efficient way to do this?

Should I load all data at the launch of the application? In my opinion this would not be a good idea considering that would require many different threads pulling from different parts of the DB all at the same time (or synchronously chained) at the onset. I am concerned this would slow the app's launch considerably.

Additionally, I think to update data, the viewDidLoad() and viewDidAppear() pulls couldn't be wholly removed anyway. In fact, I do not really see any particular benefit in doing a full load at the application launch, but I wanted to be doubly sure that I am correct in this assessment and am not missing anything.

Is there any benefit to doing the load this way? Is there any downside to doing it the way I have it set up already?

Robert Harvey
201k55 gold badges470 silver badges682 bronze badges
asked Nov 9, 2017 at 16:43
2
  • You haven't defined better/more efficient in your specific context. Do you want the app to load faster or to run more quickly once it is loaded (those two things might be mutually exclusive)? Commented Nov 9, 2017 at 17:23
  • @RobertHarvey I mean in terms of loading faster Commented Nov 10, 2017 at 18:34

1 Answer 1

2

One approach that I've used and seen used for this kind of thing is that you can load the application and start background threads that start pre-fectching data that you know you will need. Typically, you load the data for the initial view before displaying it. For example, lets say you have a main page/window that has a 'messages' menu. On that messages menu, you want to show how many new messages there are. You retrieve the ids of the new messages and display the count. At the same time you start retrieving the data for each of the new messages.

This can produce a really nice user experience because often by the time the user selects to view the messages, you are done loading them. Even if you haven't finished, you have a head start which reduces the wait time.

The downside is that this is more difficult to design and implement because it requires thread coordination and your UI needs to deal with the situation that the user has selected something that is not yet loaded. One trick is to build a data layer that hides this complexity and appears just like a lazy load to the outside. You call for data and it blocks until it's available. You can also use this layer to re-prioritize the fetching based on what the user is trying to do.

answered Nov 9, 2017 at 17:44
2
  • Does XCode have something similar to async in C#? Commented Nov 9, 2017 at 17:53
  • @RobertHarvey I really have no idea. Threads were mentioned so I assume there's some way to make use of them. Commented Nov 9, 2017 at 18:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.