title: Update read-only Core Data sqlite in main bundle
body: <p>I am using a read-only Core Data sqlite from the Main Bundle, works well. When i add a new version of the database (more read-only data) to the main bundle it still reads the "Old" version of the database.</p>
  
  <p>Anyone that can help me understand why and what to do to get the new database version the current one when a current user download an update with the new version of the database?</p>
  
  <p>This is part of trying to solve the problem in this post: <a href="https://stackoverflow.com/questions/11487151/my-app-does-not-update-the-new-version-of-read-only-core-data-sqlite-database">Same problem when accessing updated database from documents directory</a></p>
  
  <p>===SOLUTION====</p>
  
  <p>I solved this by changing the name of the new database in the "new" main bundle and it works like a dream. Also, if this is an update i delete the old database in the documents directory to clean up.</p>
  
  <pre><code>- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  
      if (persistentStoreCoordinator != nil) {
      return persistentStoreCoordinator;
  }
  
  
  //===READ DATABASE FROM MAIN BUNDLE===//
  NSFileManager *fileManager = [NSFileManager defaultManager];
  
  NSURL *storeUrl = [[NSBundle mainBundle] URLForResource:kNewDB withExtension:@"sqlite"];
  
  //=== IF THE OLD DATABASE STILL EXIST DELETE IT FROM DOCUMENT DIRECTORY ===//
  NSURL *oldDatabasePathURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];
  NSString *oldDatabasePath = [oldDatabasePathURL path];
  if ([fileManager fileExistsAtPath:oldDatabasePath]) {
      //Remove old database from Documents Directory
      [fileManager removeItemAtURL:oldDatabasePathURL error:nil];
  
  }
  
  NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; 
  
  persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
  
  NSError *error;
  if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {
      // Update to handle the error appropriately.
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
      exit(-1);  // Fail
  }    
  
  return persistentStoreCoordinator;
  }
  </code></pre>