I guess you are considering this for the case when the user wants to delete some objects but there is no internet connection, right?
In this case I would suggest actually deleting those objects from the database and storing the info about those deleted objects in a different form. For instance you could have a separate entity named “XXDelayedOperation” which would have all the necessary info you need to create a NSURLRequest
. This looks like a more efficient way of handling it.
Best way to implement soft delete or archive with Core Data and server sync
-
10-06-2023 - |
Question
I am trying to sync an iphone app with a web server using two flags - synched and is_deleted as described here https://stackoverflow.com/a/5052208
When the user deletes an item in the app, I set the is_deleted flag to true. Now I want to make sure that object does not show up in my app again since it has been deleted (for example in a table view), but I need to keep the object to perform the sync. So here is the question:
What is the best way to exclude all objects with is_deleted flag from showing up in the app by default?
I can think of two options now:
Make almost every single query in the app check if the item is_deleted - does not seem very efficient at all
Find a more generic way to automatically exclude all is_deleted=YES objects from the app, for example by overriding awakeFromFetch or some other method. But I am not sure how to exclude the objects from the context but keep them in the database for my sync.
What is the best way to do this? Is #2 even possible?
Solution 2
OTHER TIPS
You're searching with NSPredicate, right? Just have every syncable class implement a default predicate that checks for your is_deleted state, and append onto the predicate to specialize for further queries.
Also: don't name it is_deleted
. Consider is_safe_deleted
or safely_removed_and_not_called_is_deleted
-- 'cause the first time you write [mo isDeleted]
when you really meant [mo is_deleted]
, you're going to have a bad time.