title: Core Data with iCloud Notifications in iOS 7
body: <p>I have added iCloud support to my app. when the user update his data I got a notification <code>NSPersistentStoreDidImportUbiquitousContentChangesNotification</code></p>
  
  <p>That's great</p>
  
  <p>However, I have these problems</p>
  
  <ol>
  <li>I can't find a <code>will</code> version of this notification that I can use to show loader for example that the database will be updated</li>
  <li>Since I can't find a <code>will</code> version, then I used the same notification to display a loader to tell the user that the database is being updated ... The problem in this notification is that it can be called several time if the content changed in iCloud is relatively large which lead me to display several loading indicator !</li>
  <li>Is there a way that I can use to trigger the update through iCloud manually?</li>
  </ol>
  
  <p>.</p>
  
  <hr>
  
  <p>I added iCloud support to Core data by doing this:</p>
  
  <p><strong>in NSManagedObjectContext</strong></p>
  
  <pre><code>_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
  _managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy;
  </code></pre>
  
  <p><strong>in NSPersistentStoreCoordinator</strong></p>
  
  <pre><code>[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSPersistentStoreUbiquitousContentNameKey:@"iCloudStore"} error:nil];
  </code></pre>
  
  <p><strong>and In <code>NSPersistentStoreDidImportUbiquitousContentChangesNotification</code> notification method</strong></p>
  
  <pre><code>- (void)persistentStoreDidImportUbiquitousContentChanges:(NSNotification *)notification
  {
      NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
      [managedObjectContext performBlock:^{
          [managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
  
          dispatch_async(dispatch_get_main_queue(), ^{
              UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
              MBProgressHUD *hud = [MBProgressHUD HUDForView:mainWindow];
              if (hud == nil) {
                  hud = [[MBProgressHUD alloc] initWithWindow:mainWindow];
              }
              [mainWindow addSubview:hud];
              hud.labelText = NSLocalizedString(@"Progress updated", nil);
              [hud show:YES];
              [hud hide:YES afterDelay:1];
  
              // Post Notification
              [[NSNotificationCenter defaultCenter] postNotificationName:RESET_APPLICATION_NOTIFICATION object:nil];
          });
      }];
  }
  </code></pre>