title: iCloud and existing Core Data store for "shoe box" app
body: <p>I have an existing app with a single Core Data store. It is similar to what Apple calls a shoe box app.
  There are many records already stored. I was able to add the necessary code easily to get iCloud integration setup.</p>
  
  <p>I build the new app on my iPod touch and on my iPad, both running iOS5.</p>
  
  <p>The iPod has the existing data. However the data doesn't show up on the iPad.
  The app has iTunes file sharing enabled, so through iTunes I drop the sqlite db on both devices.</p>
  
  <p>Now I try making changes and see if iCloud will now keep them in synch. It does not.</p>
  
  <p>How do you get your existing data on both devices and then have iCloud keep them in synch from that point forward.</p>
  
  <hr>
  
  <pre><code>    NSFileManager *fileManager = [NSFileManager defaultManager];
  
  NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:@"ABCD1234.com.yourcompany.appID"];
  
  NSDictionary *options = nil;
  
  if (nil != cloudURL) {
  
      NSString *coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:@"data"];
      cloudURL = [NSURL fileURLWithPath:coreDataCloudContent];
  
      options = [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
                 @"myApp.store", NSPersistentStoreUbiquitousContentNameKey,
                 cloudURL, NSPersistentStoreUbiquitousContentURLKey,
                 nil];
  }
  else {
  
      options = [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
                 nil];
  }
  </code></pre>
  
  <p>And I have this added to the managedObjectContext for notifications:</p>
  
  <pre><code>[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(mergeChangesFrom_iCloud:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:coordinator];
  </code></pre>
  
  <hr>
  
  <p>There are several thousand people using my app and have entered lots of data. They do not want to enter it all again. I want to deliver this new version of the app that is iCloud enabled but until I can get the data to show up on both and stay in synch there is no point.</p>