README.md

AFIncrementalStore

Core Data Persistence with AFNetworking, Done Right

This is still in early stages of development, so proceed with caution when using this in a production application.
Any bug reports, feature requests, or general feedback at this point would be greatly appreciated.

AFIncrementalStore is an NSIncrementalStore subclass that uses AFNetworking to automatically request resources as properties and relationships are needed.

Weighing in at just under 500 LOC, AFIncrementalStore is something you can get your head around. Integrating it into your project couldn't be easier--just swap out your NSPersistentStore for it. No monkey-patching, no extra properties on your models.

Incremental Store Persistence

AFIncrementalStore does not persist data directly. Instead, it manages a persistent store coordinator that can be configured to communicate with any number of persistent stores of your choice.

In the Twitter example, a SQLite persistent store is added, which works to persist tweets between launches, and return locally-cached results while the network request finishes:

If your data set is of a more fixed or ephemeral nature, you may want to use NSInMemoryStoreType.

Mapping Core Data to HTTP

The only thing you need to do is tell AFIncrementalStore how to map Core Data to an HTTP client. These methods are defined in the AFIncrementalStoreHTTPClient protocol:

Don't worry if this looks like a lot of work--if your web service is RESTful, AFRESTClient does a lot of the heavy lifting for you. If your target web service is SOAP, RPC, or kinda ad-hoc, you can easily use these protocol methods to get everything hooked up.

Getting Started

Check out the example projects that are included in the repository. They are somewhat simple demonstration of an app that uses Core Data with AFIncrementalStore to communicate with an API for faulted properties and relationships. Note that there are no explicit network requests being made in the app--it's all done automatically by Core Data.

Also, don't forget to pull down AFNetworking with git submodule update --init if you want to run the example.