title: Permanent NSManagedObjectID not so permanent?
body: <p>I'm having trouble dealing with object IDs in CoreData.  I'm using MagicalRecord for convenience and have 3 contexts: a private queue working context, a main queue context for UI and parent to the working context, and a private queue saving context that is the parent of the main context.</p>
  
  <p>My goal is to create an object in the working context, save to the persistent store, save it's objectID URL to NSUserDefaults, and then be able to pull out that MO using the objectID later on.  However, what I'm finding is that after saving the permanent ID of the object is changing.</p>
  
  <p>In the console output below you can see that after I request the permanent ID the value I get back is "F474F6EE-A225-456B-92EF-AB1407336F15/CDBaseAccount/p1" but later when I list all the objects in CD the only object there has the ID "F474F6EE-A225-456B-92EF-AB1407336F15/CDBaseAccount/p2". p1 vs p2, what happened?</p>
  
  <p>Code:</p>
  
  <pre><code>  NSManagedObjectContext *c = [NSManagedObjectContext MR_contextThatPushesChangesToDefaultContext];
    [c performBlockAndWait:^{
  
        NSArray *all = [CDBaseAccount MR_findAllInContext:c];
        NSLog(@"count: %d", all.count);
        NSLog(@"all accounts = %@", all);
  
        CDBaseAccount *a = [CDBaseAccount MR_createInContext:c];
        a.accountName = @"foo";
  
        [c MR_saveNestedContexts];
  
        NSLog(@"temp a.objectID = %@", a.objectID);
  
        NSError *error;
        if (![c obtainPermanentIDsForObjects:@[a] error:&amp;error]) {
            NSLog(@"perm id error: %@", error);
            return;
        }
  
        NSLog(@"perm a.objectID = %@", a.objectID);
  
        NSURL *u = a.objectID.URIRepresentation;
  
        dispatch_async(dispatch_get_main_queue(), ^{
            NSManagedObjectContext *d = [NSManagedObjectContext MR_defaultContext];
  
            NSArray *all = [CDBaseAccount MR_findAllInContext:d];
            NSLog(@"count: %d", all.count);
            NSLog(@"all accounts = %@", all);
  
            NSManagedObjectID *i = [d.persistentStoreCoordinator managedObjectIDForURIRepresentation:u];
            NSError *objWithIdError = nil;
            NSManagedObject *o = [d existingObjectWithID:i error:&amp;objWithIdError];
            if (objWithIdError != nil) {
                NSLog(@"existing object error: %@", objWithIdError);
                return;
            }
  
            NSLog(@"o = %@", o);
            NSLog(@"o.objectID = %@", o.objectID);
  
        });
    }];
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>  &gt; +[NSManagedObjectContext(MagicalRecord) MR_contextWithStoreCoordinator:](0xa7c9b0) -&gt; Created &lt;NSManagedObjectContext: 0x83522a0&gt;:  Context *** MAIN THREAD ***
    &gt; count: 0
    &gt; all accounts = (
    &gt; )
    &gt; -[NSManagedObjectContext(MagicalSaves) MR_saveWithErrorCallback:](0x8353de0) -&gt; Saving &lt;NSManagedObjectContext: 0x8353de0&gt;:  Context *** MAIN THREAD ***
    &gt; -[NSManagedObjectContext(MagicalSaves) MR_saveWithErrorCallback:](0x8195450) -&gt; Saving &lt;NSManagedObjectContext: 0x8195450&gt;: *** DEFAULT *** Context *** MAIN THREAD ***
    &gt; -[NSManagedObjectContext(MagicalSaves) MR_saveWithErrorCallback:](0x83522a0) -&gt; Saving &lt;NSManagedObjectContext: 0x83522a0&gt;: *** BACKGROUND SAVE *** Context *** MAIN THREAD ***
    &gt; temp a.objectID = 0x8187ee0 &lt;x-coredata:///CDBaseAccount/tF392AC6A-3539-4F39-AC53-35F9E5B3C9322&gt;
    &gt; perm a.objectID = 0x8355800 &lt;x-coredata://F474F6EE-A225-456B-92EF-AB1407336F15/CDBaseAccount/p2&gt;
    &gt; count: 1
    &gt; all accounts = (
        "&lt;CDBaseAccount: 0x844ca60&gt; (entity: CDBaseAccount; id: 0x844a4c0 &lt;x-coredata://F474F6EE-A225-456B-92EF-AB1407336F15/CDBaseAccount/p1&gt; ; data: &lt;fault&gt;)"
    )
    &gt; existing object error: Error Domain=NSCocoaErrorDomain Code=133000 "The operation couldn’t be completed. (Cocoa error 133000.)" UserInfo=0x864d8c0 {NSAffectedObjectsErrorKey=(
        "&lt;CDBaseAccount: 0x864b8c0&gt; (entity: CDBaseAccount; id: 0x86405c0 &lt;x-coredata://F474F6EE-A225-456B-92EF-AB1407336F15/CDBaseAccount/p2&gt; ; data: &lt;fault&gt;)"
    )}
  </code></pre>