perform realm migration for multiple .realm files

醉酒当歌 提交于 2019-12-11 12:04:58

问题


i have multiple realm files, (one per user logged into my app) and i need to run a migration for each realm file in the file system

      RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];

  config.schemaVersion = 1;
  config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {

    if (oldSchemaVersion < 1) {
    //do the same changes for all file.realm in the filesystem 
    }
  };


  [RLMRealmConfiguration setDefaultConfiguration:config];

  [RLMRealm defaultRealm];

how can perform a realm migration for each of the filesystem databases and not only for the default realm file?


回答1:


+[RLMRealm migrateRealm:] performs the migration for the Realm at the path specified by the configuration:

RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.schemaVersion = 1;
config.migrationBlock = ...;
config.path = @"path 1";
[RLMRealm migrateRealm:config];
config.path = @"path 2";
[RLMRealm migrateRealm:config];


来源:https://stackoverflow.com/questions/32957225/perform-realm-migration-for-multiple-realm-files

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