为多个.realm文件执行域迁移

时间:2015-10-05 20:20:04

标签: objective-c realm realm-migration

我有多个领域文件(每个用户登录一次我的应用程序),我需要为文件系统中的每个领域文件运行迁移

      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];

如何为每个文件系统数据库执行域迁移,而不仅仅是默认域文件?

1 个答案:

答案 0 :(得分:2)

+[RLMRealm migrateRealm:]在配置指定的路径上执行Realm的迁移:

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