0

I am attempting to move all of my edit operations in to their own NSManagedObjectContexts so that any background save operations can continue without accidentally committing unfinished changes. Only on confirmation do I save the changes into the parent context.

After creating my temporary context, I have to locate the 'real' object in that context -

Item *tempItem = (Item *)[temporaryContext objectWithID:[realItem objectID]];

Logging confirms that the correct Item object is located and the tempItem.name is correct. So I go ahead and use the tempItem as follows:

[editItemViewController setItem:tempItem];

However, when I try to access the tempItem property within EditItemViewController, data for the object is a fault:

<Item: 0xc249720> (entity: Item; id: 0xc39cab0 <x-coredata://BBAD105F-EA03-4593-885A-26C2FA5468AD/Item/p11> ; data: <fault>)

For example, attempting to log editItemViewController.item.name logs null.

Why is the data a fault when accessing it as a property of the view controller, when it wasn't at the time I retrieved it?

7
  • Was the importing context (temporaryContext) deallocated/released?
    – Dan Shelly
    Apr 26, 2013 at 19:31
  • I don't think so - I'm using arc Apr 26, 2013 at 19:55
  • Try importing the object you need by its objectID in your view controller and see if this makes a difference. If you are releasing your temporary context before using the item, the item will be un-faulted.
    – Dan Shelly
    Apr 26, 2013 at 20:00
  • It does make a difference. Why would the context be released when the object is not? Apr 26, 2013 at 20:21
  • I don't know the entire scope of your implementation so it is hard to say. But, by the name of the context, it's life span is probably the function it is declared in, after that your fetched objects are orphaned.
    – Dan Shelly
    Apr 26, 2013 at 20:25

1 Answer 1

0

keep temporaryContext as a strong property in your editItemViewController

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.