0

I am working on an application where I have a connection to a database. The database contains from 300MB to 4GB worth of data as each customer has their own database. My issue that I am having is in gathering the data, because of the potential database size, just downloading and storing the information locally isn't possible. The data can get quite complex and can vary. For an example:

A customer has a Job and they want to search for that job from the app. I then fetch a list of jobs matching the search criteria. The customer sees the job they want to view and I start the gathering process.

This job can potentially touch many tables, sometimes repeatedly..

There is the jobs table, a relational table to map to a person. Then there is another table that contains non-customer relational information, then there are calendar events associated to the job, which in tun can associate different people. Then there are emails attached to the job, which in turn can bring in additional people and events.

So I have a working model that gathers all of this information. The problem I have is that I cannot figure out a great method of signaling to my view that the data is completely downloaded. My initial thought was to use the NotificationCenter to message when the certain parts of the task were finished, allowing the core Job object to notify the view when everything was complete.

I know this is a pretty generalized question, but I'm honestly stumped as to how to take an unknown number of table results and translate that into a notice that my app can actually use.

2
  • It's a tricky question, with no simple answer. One way or another you've got to keep track of everything you've requested and not yet received. I have an app with similar complexity, but the framework is most certainly entirely different from yours, so I can't offer more than that general advice.
    – Hot Licks
    Feb 14, 2014 at 17:51
  • I recommend drawing everything out on paper. All the view controllers, their data, how to get from screen A to screen B and so on. Once you have an accurate chart representation on paper, you can start working on the programming side one step at a time.
    – sangony
    Feb 14, 2014 at 17:54

2 Answers 2

1

My initial recommendation would be Core Data. It's designed for this kind of problem. No, I'm not saying to download the entire database into Core Data. I'm saying to use Core Data to manage your object model, because that's what it's good at.

As you receive data from the server, compose it into NSManagedObjects and stick them in the data store. On the UI side, create an NSFetchedResultsController to keep you informed as the data updates asynchronously. You don't necessarily need to persist this store. You could just keep it in memory and throw it away whenever you're done with the query, but keeping it on disk could be a nice caching solution. Again, don't think of Core Data as "a local database." Think of it as a model persistence engine that you can query for objects.

One advantage of this model is that you can provide the best available data to the user as it becomes available. But say you really don't want to get the information until it's all available. That's fine, too. Just let the network side keep updating its context, and then only save it when everything's complete. That way NSFetchedResultsController gets a single atomic update. The nice things with Core Data is that it has these concepts built in, so you can adjust your update strategy without requiring massive redesign.

1
  • I would say that rather than using Core Data for everything, consider placing some large files in the Caches directory where iOS can delete them if it needs the space. Of course, this means that the app must be prepared to find a file missing and re-fetch it, but it makes the app a "good citizen" (and may make it easier to clear Apple's acceptance criteria).
    – Hot Licks
    Feb 14, 2014 at 18:02
0

The Notification Center will work great for this.

Post the notification at logical points in your data load to trigger a UI update for your users.

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.