Note that there are some explanatory texts on larger screens.

plurals
  1. POUndoing Core Data insertions that are performed off the main thread
    primarykey
    data
    text
    <p>I'm working on some code that uses an <code>NSOperation</code> to import data. I'd like for the user to be able to undo the <code>NSManagedObject</code> instances that are created during the import operation.</p> <p>From what I can tell, it's impossible to use the <code>NSManagedObjectContext</code> <code>-undoManager</code> for any operations that are performed off of the main thread. From the <em>Core Data Programming Guide</em> section on <em>Use Thread Confinement to Support Concurrency</em>, we have these two conditions:</p> <blockquote> <ol> <li>Only objectID should be passed between managed object contexts (on separate threads)</li> <li>Managed objects must be saved in a context before the objectID can be used.</li> </ol> </blockquote> <p>This makes sense since the managed objects need to be moved from private storage (<code>NSManagedObjectContext</code>) to public storage (<code>NSPersistentStore</code>) before they can be shared.</p> <p>Unfortunately, the <code>-save:</code> message also causes any managed objects in the undo stack to be removed. From the <em>Memory Management Using Core Data</em> section of the same guide:</p> <blockquote> <p>Managed objects that have pending changes (insertions, deletions, or updates) are retained by their context until their context is sent a save:, reset , rollback, or dealloc message, or the appropriate number of undos to undo the change.</p> </blockquote> <p>I've tried several things to work around this limitation, and everything eventually leads back to bulk of the work happening on the main thread (and spinning beach balls.) Any clues to getting undo working with objects created off the main thread would be very much appreciated.</p> <p>--</p> <p>An enhancement Radar has been submitted: <a href="http://www.openradar.me/8977725" rel="noreferrer">rdar://problem/8977725</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload