Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a core data NSManagedObject after resuming from background crashes the app
    text
    copied!<p>I'm using core data and have found the app sometimes crashing after resuming from background. I've identified the crash occurring inside a block method body when I try to access a property on a <code>NSManagedObject</code> subclass. </p> <p>I have a property which holds a reference to a <code>NSManagedObject</code> subclass. </p> <blockquote> <p>@property(nonatomic,strong) CalItem *calObject;</p> </blockquote> <p>To reproduce the crash I first need to call the child viewController(<code>NoteViewController</code>) passing a block (<code>NoteTextBlock</code>).</p> <pre><code>NoteViewController *noteViewController = [[NoteViewController alloc]initWithNote:self.calObject.note NoteTextBlock:^(NSString *noteText) { self.calObject.note = noteText; //crashing here }]; </code></pre> <p>Then send the app to background and resume it. Afterwards in the NoteViewController I'll return a message to the calling viewController.</p> <pre><code>if (self.noteTextBlock) { self.noteTextBlock(trimmedString); } </code></pre> <p>When the block returns and the line <code>self.calObject.note = noteText</code> gets executed the app crashes.</p> <p>So apparently you can't put a block on the stack, quite and resume the app and then continue with what was defined inside the block ? Or am I just doing something wrong here ?</p> <p><strong>Edit:</strong><br> <code>*** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0xb253100 &lt;x-coredata://C2304B7C-7D51-4453-9993-D33B9113A7A5/DTODay/p57&gt;''</code></p> <p>The block is defined like this inside the child viewController:<br></p> <pre><code>@property(nonatomic, copy)NoteTextBlock noteTextBlock; </code></pre> <p><strong>Edit2</strong><br> This is what I get when I set a breakpoint on the line where it crashes.<br> <code>(lldb) po self.calObject</code><br> <code>$2 = 0x0b4464d0 &lt;DTODay: 0xb4464d0&gt; (entity: DTODay; id: 0xb489d00 &lt;x-coredata://C2304B7C-7D51-4453-9993-D33B9113A7A5/DTODay/p57&gt; ; data: &lt;fault&gt;)</code></p> <p>I'm using the MagicalRecord lib to manage all the Core Data stuff.</p> <pre><code>- (void)applicationDidBecomeActive:(UIApplication *)application { if ([NSManagedObjectContext MR_defaultContext] == nil || [NSManagedObjectModel MR_defaultManagedObjectModel] == nil || [NSPersistentStoreCoordinator MR_defaultStoreCoordinator] == nil || [NSPersistentStore MR_defaultPersistentStore] == nil ) { //coming back from background, re-init coredata stack [MagicalRecordHelpers setupCoreDataStackWithAutoMigratingSqliteStoreNamed:DBNAME]; } </code></pre>
 

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