Search code examples
core-datansmanagedobjectnsmanagedobjectcontextpersistent-storage

is there a way to see which objects in a managedobjectcontext have not yet been added to the persistent store?


is there a simple and efficient/fast way to query a managedobjectcontext to get an array of all the managedobjects in the context that have not yet been added to the persistent store?

i ask this because i would like to be able to save nsmanagedobjects that have been added to the MOC only if they conform to certain criteria. basically i want to be able to do this so that if some unexpected event happened before my managed object attributes were properly populated, i can catch this fact and purge the object(s) before saving the context. given the complexity of the navigation possible in the app, i'd like to have a look at the data to be sure they are good before i save.

i suppose i could also do this with some kind of validation rule and a flag field that doesn't get set until i am sure the user has added all the data to the record, but i don't yet know how to implement this... any help much appreciated.


Solution

  • The insertedObjects method of NSManagedObjectContext returns the set of objects that have been inserted into the context but not yet saved in a persistent store.