Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A UIManagedDocument will save, well, basically, when it feels like it; you don't have control as to when that occurs. It will, however, certainly save on application termination, which is why you see the inserts when you restart.</p> <p>As a result, while you may think you have permanent object ids, they're actually likely temporary, and thus can't be fetched. Simply dumping them via an NSLog would validate this, as temporary object ids show up as such when logged.</p> <p>To force them to be permanent and thus usable, try the following after performing your additions. Assuming you have a UIManagedDocument as an ivar:</p> <pre><code>- (void)performUpdate { NSManagedObjectContext * context = self.managedDocument.managedObjectContext; NSSet * inserts = [context insertedObjects]; if ([inserts count]) { NSError * error = nil; if ([context obtainPermanentIDsForObjects:[inserts allObjects] error:&amp;error] == NO) { NSLog(@"BAM! %@", error); } } [self.managedDocument updateChangeCount:UIDocumentChangeDone]; } </code></pre> <p>Obviously, you'd replace the error handling with something a bit better here. The UIManagedDocument will now save at some point in the future (again, you have absolutely no control over when that'll happen, we're just asking it to do so in the last line, in the same way that an undo manager would), but newly-inserted objects should now have usable permanent ids and fetches should work properly.</p> <p>And yes, this seems a bit odd to me too, but this appears to be the correct way to do things with a UIManagedDocument in play.</p> <p>Frankly, I'd love for someone to tell me I'm incorrect and provide a better solution.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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