core data - CoreData and Shared ManagedobjectContext in TabBar iphone app -


I am working on a coredata iphone tabbar application, and the appropriate managed object contexts for all ideas and sub-views I am passing. Create a new record for unit A and when Unit A was not saved by the user, then I need to create another unit B using the same shared reference. Now, my problem is that if I save the reference of Unit B, then this unit will also save A. I do not want to save the unit A, or as long as the user does not want to save it.

I can see only one way the unit is making different references for B or something ....

please

>

You can:

  1. Use different references PRO: Do you want Con: Complexity has been added and you can not make relationships easily.
  2. Pass the object in a context in a reference, near zero, when you insert an object. Then add it to the context when you want to save. PROF: Do you want to: All functionality provided by reference to the above and references, such as undo support.
  3. Just remove the object-A, the user decides they do not want to. PRO: Simple and Safe Conn .: In the object graph, relationships must be allowed to erase object-A. I. Other objects that you want to keep, object-A can not exist. When designing the model you have to keep this in mind.

I almost always go with (3). This is the simplest and safest way to date. Since it imitates what the user is actually doing, i.e. creating a data object and then deciding to throw it, this is also a good design practice.


Comments