title: iCloud & CoreData: Notification when changed to iCloud Store (First Launch with existing iCloud Data)
body: <p>I'm trying to receive a message when the local store changes to the iCloud Store.</p>
  
  <p>This is a critical event. So my use case is a new device receiving the iCloud Store after starting with an empty store. I would like to notify the view to update with the received content.</p>
  
  <p>I initialize my managed object context like this:</p>
  
  <pre><code>[self.managedObjectContext.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                                     configuration:nil
                                                                               URL:self.storeURL
                                                                           options:@{ NSPersistentStoreUbiquitousContentNameKey : @"iCloudStore", [NSNumber numberWithBool:YES]: NSMigratePersistentStoresAutomaticallyOption,
                                                                                      [NSNumber numberWithBool:YES]:NSInferMappingModelAutomaticallyOption}
                                                                             error:&amp;error];
  </code></pre>
  
  <p>My next step is to get the following notifications:</p>
  
  <pre><code>NSNotificationCenter *dc = [NSNotificationCenter defaultCenter];
  [dc addObserver:self
         selector:@selector(storesWillChange:)
             name:NSPersistentStoreCoordinatorStoresWillChangeNotification
           object:psc];
  
  [dc addObserver:self
         selector:@selector(storesDidChange:)
             name:NSPersistentStoreCoordinatorStoresDidChangeNotification
           object:psc];
  
  [dc addObserver:self
         selector:@selector(persistentStoreDidImportUbiquitousContentChanges:)
             name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
           object:psc];
  </code></pre>
  
  <p>I thought that implementing the update ui in the <code>name:NSPersistentStoreCoordinatorStoresDidChangeNotification</code> should do the thing. But somehow it appears that this is what I intended to do.</p>
  
  <p><strong>Edit:</strong>
  With the related post in the accepted answer I could solve my issue</p>
  
  <p>I check the notifications userdict in</p>
  
  <p>like this: <code>storesDidChange:</code></p>
  
  <pre><code>NSNumber *storeVal = [note.userInfo objectForKey:NSPersistentStoreUbiquitousTransitionTypeKey];
      if (storeVal.integerValue == NSPersistentStoreUbiquitousTransitionTypeInitialImportCompleted) {
          //you are now in sync with iCloud
          NSLog(@"On iCloud Store now");
          [self.delegate storeHasChanged];
      }
  </code></pre>