Reputation: 10759
I seem to be having an issue with removing items from Core Data using RestKit. I make a call to get some MovingObjects based on an lat and lng, via restkit. They get stored in CD. When I want make the call again, I manually delete all MovingObjects from CD, then make the call again.
What I want to happen is make the initial call to get all MovingObjects Then call it again and have Restkit keep the ones in CD if they match those returned again, add any I don't have, but DELETE the rest in CD that aren't returned from the second call.
I am trying to only store MovingObjects that are fresh as some MovingObjects might move out of a geo-fenced area.
EDITED ======== To be clear. I do NOT want to delete objects on the server. I ask the server, "give me all the objects you see in a geofenced area based on this lat, lng". The server responds with a list of 20 objects. I think poll again every 15 seconds and ask again "give me all the objects you see in a geofenced area based on this lat, lng" it responds. But this time it responds with 10 objects, five of which are the same as as last time and five new ones.
What I need to do or want Restkit to do is
1. delete all the objects out of CD and replace with the 10 from the second call.
OR
2. delete the 10, from CD, that weren't returned on the second call, leave the 5 persisted objects alone and add the new 5 objects.
I am thinking since these are continuously transient objects that I should not be storing them in CD.
Upvotes: 3
Views: 1545
Reputation: 2755
Although the reference docs that Wain refers to are a bit confusing, setting up a RKFetchRequestBlock
is in fact the way to get RestKit
to delete orphaned objects locally, and NOT on the server. I posted and similar question to this here and did a self-answer with some sample code.
Upvotes: 0
Reputation: 119031
You want to look at the section "Fetch Request Blocks and Deleting Orphaned Objects" : http://restkit.org/api/latest/Classes/RKManagedObjectRequestOperation.html. It requires you to be using an RKObjectManager and for your objects to have a unique identity which is added to your mappings, and describes the way that you tell RestKit how to find content in the data store that should be deleted (and it checks and doesn't delete things that it just received from the server).
Upvotes: 1