AFIncrementalStore with Parse

1.1k Views Asked by At

I am developing an social app on iOS that have many-to-many relation, local persistency, and user interaction. I have tried using native Parse API in iOS and find it too cumbersome to do all the client-server logic. So my focus shifted to finding a syncing solution.

After some research I found AFIncrementalStore quite easy to use and it's highly integrated in CoreData. I just started to work on this and I have two questions to ask:

1) How to do the authentication process? Is it in AFRESTClient? 2) How to set up AFRESTClient to match Parse's REST API? (an example would be great!)

P.S. I also found FTASync, which seems to be another solution. Any thought on this framework?

Any general suggestion on client-server syncing solutions will be highly appreciated!

Thanks,

Lei Zhang

2

There are 2 best solutions below

3
Eric Hedstrom On BEST ANSWER

Take a look at this StackOverflow question and at Chris Wagner's article on raywenderlich.com.

The linked SO question has examples for how to include the authentication token with each request to Parse. So you'll just need to have the user log in first, and store their token to include it with each subsequent request.

Chris Wagner's tutorial has a sample AFHTTPClient named SDAFParseApiClient to communicate with the Parse REST API. You'd have to adapt it to be an AFRESTClient subclass, but it should give you a start.

Some other thoughts between the two solutions you're considering:

  • AFIncrementalStore does not allow the user to make any changes without a network connection, while FTASync keeps a full Core Data SQLite store locally and syncs changes to the server when you tell it to.
  • FTASync requires you to make all your synched managed objects subclasses of FTASyncParent, with extra properties for sync metadata. AFIncrementalStore keeps its metadata behind the scenes, not in your model.
  • FTASync appears not to be widely used and hasn't been updated in over a year; if you use it you will likely be maintaining it.
5
sbonami On

Back with iOS 5 Apple silently rolled out NSIncrementalStore to manage connection between APIs and persistent stores. Because I couldn't word it better myself:

NSIncrementalStore is an abstract subclass of NSPersistentStore designed to "create persistent stores which load and save data incrementally, allowing for the management of large and/or shared datasets". And while that may not sound like much, consider that nearly all of the database adapters we rely on load incrementally from large, shared data stores. What we have here is a goddamned miracle.

Source: http://nshipster.com/nsincrementalstore/

That being said, I've been working on my own NSIncrementalStore (built specifically for Parse and utilizing the Parse iOS/OS X SDK) and you're welcome to check out/use/contribute to the project at https://github.com/sbonami/PFIncrementalStore.