Retrieve and store versioned data

Hi all,


I'm looking for some advice on Best Practice for the retrieval and storage/use of data from a web service. At this stage, more of a conceptual question, than a request for specific code.


Here are the major points:

  • The app will use a data model to populate both a table view and a mapkit view with annotations
  • The app will be packaged with an initial (default) set of data
  • The app should check for updates to this data from the external web service
  • Where an update is available, it should be downloaded and used. The data should persist.
  • Development will be XCode 9/Swift 4. There are no legacy/compatability issues


I'm unsure about the best way to accomplish this. Some questions are:

  1. Should I package the default data as a JSON file and load this at runtime each time the app loads to populate tables etc or would this be inefficient?
  2. I obviously don't want to download data that is not a newer version than the local copy.. what is the best way to check this so that I only download updates?
  3. Would downloading a complete JSON file form the web service and replacing the default data file be a good option? Should I retrieve the data in another way? Should I keep a backup of the original file?
  4. Would you run the check and download the data while the app is loading, or load what is available locally and then update in the background?


I'd really appreciate any insight people could provide in terms of the best way to start designing this process.


Please let me know if I've left out any crucial information.


Regards

NB

Replies

I'll try to provide some anwers.


1. Should I package the default data as a JSON file

My personal preference wiould be to create your own data maodel ; you will get more control and avoid problem if ever data maodel changes on web service


2. what is the best way to check this so that I only download updates?

Do you control the web server side ? If so, you could set a date of update and compare.

If not, you will have to chack all data to see if it has changed and then update appropriately


3. replacing the default data file

This depends on how you handle point 1. But that could be a problem if the data structure of the web file has changed


4. Would you run the check and download the data while the app is loading

You should avoid. It is advised to keep the app launching as short as possible :

// WWDC15 CocoaTouch Optimization: Need to keep this ()func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) very short to return as fast as possible, so that app launches quickly


Hope that helps.

Ah yes, I forgot to meantion that I will be creating the web service myself, so can control the json file as well as provide other queries if required.


So you're saying that creating a data model and using Core Data to translate the json into it and power the tables would be a better option than just relying on json files?


Thanks.

Yes, that would be my personal preference, to avoid a strong coupling between the server world and the app world, even though you control both so you could accept this tight coupling. But I think it may hinder you for future evolutions of your app.


So I would:

- create a data model for the app (with or without CoreData, depending on how comples the data structure is)

- feed it with data you get from server with JSON.