Nick Harris

iOS Client Side Sync

leave a comment »

There’s been much ado about writing sync type services for mobile from the server side, but I haven’t seen much about how to implement them on the client side. This is an overview post to see if there’s more interest in how I’ve done things in the past.

Main point: Map your sync data well with Core Data and use NSFetchedResultController’s.

Hit me up on Twitter if a deeper dive into this is something of interest.

Most of my iOS experience has been writing enterprise apps used by large companies as opposed to individual consumers. At NewsGator I wrote the first three versions of NewsGator Social Sites for iOS which connected employees to their companies Microsoft Sharepoint portal. The original was written with iOS 2.1. The amount of data that needed to be “synced” far outreaches anything else I’ve ever worked on.

Social Sites had a co-worker concept that was similar to friends or people you follow on Twitter. Those people could post to a timeline with text, pictures and videos, then have other co-workers comment on those posts (also with pictures and video) – all within the company firewall.

There was also the concept of Communities that had their own timeline of posts and comments along with a list of members.

On top of that there were also Sharepoint libraries of documents, photos, task lists, polls or any N number of object types a company decided to add to their Sharepoint portal. All of these could be associated with both individuals as well as Communities.

An incredible amount of data constantly changing.

I’ve had a lot of experience with SQL databases. I love SQL. But when I had to decide between using SQL or Core Data, I chose Core Data specifically for the use of NSFetchedResultController’s.

My approach was to map the data in Core Data as close as possible to how it was represented on the server. I could then create specific NSFetchedResultController’s for each view controller in the app. All of the “sync” would happen in the background and if something that a particular view needed to know about changed, it would be notified via the NSFetchedResultController.

What this bought me was a separation between the networking code, the local data preservation code and the view controller code.

It worked wonderfully.

It’s been over a year since I’ve work on that code, but if there’s interest, I can put something together that’s more in depth which I can share.


Written by Nick Harris

April 23, 2014 at 5:55 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: