4

I simply want to create entities yet not to be saved, only inspect them.

Can I create a temporary context for those? Is there a way to move them into the persistent context once I decided to store them?

And the point: are these features available trough MagicalRecord API?

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172

1 Answers1

10

Create a new NSManagedContext that has parentContext property set to your main context, and create new objects in the new context - you can do everything you want with those objects, then later either save the new context (this will move the objects to the main context) or just discard it - the objects will be gone.

Seems that there stands an +(NSManagedObjectContext*)MR_contextWithParent: for that in MagicalRecord.

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
Peter Sarnowski
  • 11,900
  • 5
  • 36
  • 33
  • Thanks, so the point is parentContext. Gonna scan MagicalRecord docs for that. – Geri Borbás Jan 16 '14 at 10:26
  • 1
    Be warned, there are issues with parent/child contexts that you may bump into. See e.g. http://wbyoung.tumblr.com/post/27851725562/core-data-growing-pains – Simon Jan 16 '14 at 11:02
  • @Simon the blog post is rather old, and I use nested contexts extensively, hadn't noticed those problems... – Peter Sarnowski Jan 16 '14 at 11:29
  • @Peter I think that whether you notice them or not depends a lot on your setup. I still run into them, so I thought they were worth mentioning. – Simon Jan 16 '14 at 11:40
  • Which context do you use as the parent context in this case? The default context? The root context? Also you mention issues w/ parent child MOC's, still the case? Possibly better to just put temp data (not yet to be saved) in regular variables (not an entity) and only create and save the entity if the user hits save? – lostintranslation Nov 27 '15 at 01:19