iosswiftcore-data

iOS Swift Preloading Application Data


I am working on an application that is dependent on data that should be loaded from our remote servers on the application first launch. Currently I simply fetch data using few different functions and then loading the data into different object arrays. I did some research about preloading data but everything I found has specifically to do with preloading data using CoreData objects. Here are my questions:

  1. Should I load data using CoreData objects? Is it OK to load data into arrays of custom objects?

  2. What are the pros and cons of loading that data into arrays of custom objects?

  3. What are the pros and cons of loading the data into CoreData objects?

  4. How should I get the application to load the data, make sure each function has completed and the data has been loaded before the application moves on with loading the primary view?


Solution

  • Both variants of loading data to CoreData objects and into array of custom objects are ok, but mainly serves different purposes. Storing data using CoreData objects is the most common way of storing persistent data. Thus if you might have to support offline mode work of your application in future, that's the right choice. If you know for sure that your application should work only in case Internet access is available, there is no need to support data persistence and storing data into array of custom objects is absolutely enough.

    Talking about data server requests chaining. You can perform synchronous calls in application:didFinishLaunchingWithOptions: method. In such case application will display launch screen while data is loading. But that's probably not the best solution because user might be confused what is happening so long period of time before application actually starts. If I were you I would rather create loading screen with some kind of progress bar that shows user that data is loading and how much data is already loaded. For chaining requests in such controller I would use ReactiveCocoa. You can find an example of how to do so by this link.