Migrate Persistant Store Crash

本小妞迷上赌 提交于 2019-12-02 06:21:34

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!