Using AFIncrementalStore without NSFetchedResultsController or NSArrayController

156 Views Asked by At

I'm trying to fetch some data without NSFetchedResultsController or NSArrayController. The problem is that due to AFIncrementalStore's asynchronous nature, I'm always getting stale data (or no data if it hasn't been fetched) data.

Is there any recommended approach to handle this problem?

2

There are 2 best solutions below

0
Arek Holko On

I think that preferred approach to this problem is to use NSFetchedResultsControllers (at least on iOS). If you really don't want to use it, you might want to subscribe to one of these notifications, depending on the granularity of changes you expect to receive:

  • NSManagedObjectContextObjectsDidChangeNotification
  • NSManagedObjectContextDidSaveNotification

and then refetch the data when one of these notifications is posted.

0
h4xnoodle On

You can also try using the AFIncrementalStore notification for notification on when remote data has been fetched in order to update the UI and your objects.

AFIncrementalStoreContextDidFetchRemoteValues etc

https://github.com/AFNetworking/AFIncrementalStore/blob/master/AFIncrementalStore/AFIncrementalStore.m#L29