Reputation:
Can we save a particular NSManagedObject
intead of whole NSManagedObjectContext
?
Upvotes: 2
Views: 490
Reputation: 4019
Core Data is not for object serialization, it is an object graph serialization. That is an important distinction. Once you have an NSManagedObject
it is associated with a context, and Core Data handles saves at context level since that is the only way it guarantee any sort of object graph consistency. In other words, you can't save individual objects because if they have relationships with other objects you would need to also save those objects and it quickly cascades out to the whole graph.
You seem to be worried about crash recovery. If the app crashed and the user relaunched it would they expect to see just the items they saved, or everything that was on the screen before they crashed? If it is the former you should just delete them at save time and remove them from the users view (with some animation), if it is the later you should commit out everything, and potentially delete the objects you are not interested in at another time.
Upvotes: 2
Reputation: 540135
No. Saving a managed object context saves all changes made to the context, and there is no API to save a single object.
What you perhaps can do is to create a separate context, create or modify an object there and save that context.
Upvotes: 2