views:

324

answers:

1

I'm developing an iPhone app that uses a user account and a web API to get results (json) from a website. The results are a list of user's events. Just looking for some advice or strategies - when to cache and when to make an api call... and if the iPhone SDK has anything built in to handle these scenarios.

When I get the results from the server, they populate an array in a controller. In the UI, you can go from a table listing view, to a view of an individual event result - so two controllers share a reference to the same event object. What gets tricky is that a user can change the details of an event. In this case I make a copy of the local Event object for the user's changes, in case they make an error. If the api call successfully goes through and updates that event on the server, I take these local changes from the Event copy and set the original Event object to match with setters. I have the original controller observing if any change is made to the local Event object so that it can reflect it in the UI. Is this the right way of doing things? I don't want to make too many API calls to reload data from the server, But after a user makes an update should I be pulling down the list again with the API call? ...I want to be careful that my local objects don't become out of sync with the remote. Any advice is appreciated.

+2  A: 

I took a similar approach with an app I built. I simply made a duplicate version of the remote data model with Core Data, and I use etags on the backend to prevent sync issues (in my case, it's okay to create duplicate records).

It sounds like you're taking a good approach to this.

greenisus