开发者

Is there a simple way to clear older Core Data entities?

I'm currently using RestKit and CoreData to pull down a collection of 'Towns' from a RESTful web 开发者_开发百科service. However, I have noticed that if a particular town is removed on the web service it will still appear in my NSFetchedResultsController/UITableView.

It's quite obvious that this record is never 'touched' after receiving the list of new towns from the service, as there is no reference to it in the JSON payload.

Is there a simple way I can remove the 'old' town entities without deleting all the records before doing a fresh update from the service? My ultimate aim is to have an NSFetchedResults controller which exactly matches that returned by the service.


You could fetch all your Towns before handling the JSON payload. Then as you do whatever you do with the JSON, remove the corresponding Town from your array of towns. Then when you're done, the towns that are left in your array are the towns that weren't used. You can then iterate over them and delete them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜