I have a switch that turns iCloud on or off for an iOS 7 app. iCloud sync works fine. When iCloud is on and I turn it off, I call this code:
- (void)migrateiClou
Try This
[psc removePersistentStore:currentStore error:nil];
[psc migratePersistentStore:currentStore
toURL:self.store
options:options
withType:NSSQLiteStoreType
error:&error];
[psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:self.store
options:options /* options for local store */
error:nil];
UPDATE: new solution
NSPersistentStoreCoordinator * persistentStoreCoordinator = self.persistentStoreCoordinator;
NSPersistentStore * persistentStore = [[persistentStoreCoordinator persistentStores] firstObject];
NSMutableDictionary * localStoreOptions = [[self localPersistentStoreOptions] mutableCopy];
[localStoreOptions setObject:@YES forKey:NSPersistentStoreRemoveUbiquitousMetadataOption];
[[NSFileManager defaultManager] copyItemAtPath:persistentStore.URL.path toPath:[self storeURL].path error:nil];
NSPersistentStoreCoordinator * newPersistentStoreCoordinator;
newPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
[newPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[self storeURL]
options:localStoreOptions
error:nil];
[self setPersistentStoreCoordinator:newPersistentStoreCoordinator];
[self setupManagedObjectContext]; //initialize new moc with new persistent store coordinator