Basic data with recommended web services template?

I am writing an iOS app that uses data provided by a web service. I use basic data for local data storage and storage, so some basic data set is available to the user if the network is not available.

When creating this application, I read a lot of posts about basic data. Although there seems to be a lot of this on the mechanics, I have seen fewer general principles / patterns for this.

I am wondering if there are good recommendations for a recommended interaction model.

For example, the user will be able to create new objects in the application. Suppose the user creates a new employee object, the user usually creates it, updates it, and then saves it. I saw recommendations that update each of these steps on the server → when the user creates it, when the user makes changes to the fields. And if the user cancels at the end, a deletion is sent to the server. Another recommendation for the same operation is to save everything locally and only send a full update to the server when the user saves.

In this example, I am wondering if there are any general recommendations / patterns on how to handle CRUD operations and ensure their synchronization between the web server and coredata.

Many thanks.

+6
design-patterns iphone web-services core-data
source share
3 answers

You might want to familiarize yourself with “transactions” - this is basically a grouping of several actions / changes as one atomic action / change. This helps to avoid partial storage, which can lead to inconsistent data on the server.

Ultimately, this is a very big topic, especially if the server data is distributed among several clients. In the simplest case, you would like to decide on key policies. Does last salvation persist? Is there any concept of remotely held object locks in a server data store? How is a conflict resolved when two clients, say, edit the same property of the same object?

As for how things are on the iPhone, I would agree with the oculus that “Done” provides a natural point for constant changes on the server (in a separate thread).

0
source share

I think the best approach when you mention is to store data only locally until the user adds a new record. Sending each field edit to the server is somewhat excessive.

The general idiom of iPhone apps is that there is no such thing as Save. The user will usually expect things to be done at some reasonable point, but they are not provided to the user as a savings as such.

So, for example, imagine that you have a user interface that allows the user to edit some kind of record, which will be saved in the local kernel data and also sent to the server. At the moment when the user leaves the user interface to create a new record, they can click the "Finish" button (NB is usually not called "Save"). At the moment when they clicked "Finish", you will want to start recording the main data, as well as start push to the remote server. The pus h server does not necessarily cause the user interface to freeze or make it wait until it completes - it is better if you continue to use the application, but this happens. If the update failure on the server failed, you can report it to the user or do something suitable.

A good question is to ask yourself when you plan to write granularity to the main data and / or the remote server: what will happen if the application crashes or the phone does not work, in any specific places of the application? How much data can lose? Good applications reduce the risk of data loss and can be restarted in a very close state to the point that they were previously after the release for some reason.

+1
source share

Be prepared to rip out your hair quite a bit. I worked on this, and the problem is that Core Data samples are pretty simple. The moment you navigate to a complex model and try to use the NSFetchedResultsController and its delegate, you encounter all the problems when using multiple contexts.

I use it to populate the data from your web service in the background "block", and the second to use in the table - you most likely end up using the table view for the main list and the detailed view.

Remove the use of blocks in Cocoa if you want your application to respond while receiving or sending data to / from the server.

+1
source share

All Articles