I am in the process of writing an NSIncrementalStore that is backed by a REST service. It works nicely for POSTing and GETing objects, but when DELETEing them I encounter the following problem:
- test calls
[context delete: object]; context.deletedObjectscontainsobject(as one would expect)- test calls
[context save: &error]; - iOS calls
NSIncrementalStoresexecuteRequest:withContext:error:with aNSSaveChangesRequest; when the call arrives bothcontext.deletedObjects == nilandsaveChangesRequest.deletedObjects == nil, so my code cannot find out which objects to DELETE from the server.
How can it happen that deletedObjects is set to nil between the call to the context's save and its invocation its NSIncrementalStore?
UPDATE possible cause: object.objectID is still a temporaryID following save. The NSIncrementalStore is currently obtaining object IDs from newObjectIDForEntity:referenceObject: and the description from Apple's documentation somehow does not seem to apply yet:
New objects inserted into a managed object context are assigned a temporary ID which is replaced with a permanent one once the object gets saved to a persistent store.
The trouble was that I did not yet store enough information on the server to recreate (permanent) object IDs during fetches.
This solves the problem in
NSIncrementalStore:When
executeRequest:withContext:error:receives anNSSaveChangesRequestit extracts (in my case) reference strings from saved objects withreferenceObjectForObjectID:and stores these (along with objects' other attributes) on the server.When
executeRequest:withContext:error:receives anNSFetchRequestit obtains reference strings (along with objects' other attributes) from the server and recreates objects with[context objectWithID: [self newObjectIDForEntity: entity referenceObject: referenceString]].