2016-01-31 73 views
3

迁移已发货的已更新iOS应用程序的Realm DB变更的步骤是什么?为迁移iPhone应用程序迁移Realm数据库的步骤

在发送Realm.io数据库应用程序之前,是否有任何先前的步骤?

下面是关于核心数据 Steps to migrate Core Data databases for shipped iPhone apps的类似问题,但我正在寻找迁移Realm数据库。

这里去的崩溃日志:

***终止应用程序由于未捕获的异常“RLMException”,原因:“迁移所需的对象类型‘ExampleRealm’由于 以下错误: - 属性'值'已添加到最新的对象模型中。'

+0

这可能取决于您的数据存储现在的样子。你有你的数据在核心数据存储或NSUserDefaults?除此之外,请参阅Realm入门指南。这个很不错。 – Moshe

+0

没有使用核心数据。由于该应用程序仍处于开发阶段,同时部署了专门构建并更改了领域数据库结构。应用程序会崩溃,除非我们进行全新安装。 – silentBeep

+0

什么样的崩溃?你可以在原始问题中分享一个日志吗? – Moshe

回答

2

根据the Realm documentation,有一些如何在Realm中进行迁移的示例。

从示例代码,还有就是:

// define a migration block 
// you can define this inline, but we will reuse this to migrate realm files from multiple versions 
// to the most current version of our data model 
RLMMigrationBlock migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) { 
    if (oldSchemaVersion < 1) { 
     [migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) { 
      if (oldSchemaVersion < 1) { 
       // combine name fields into a single field 
       newObject[@"fullName"] = [NSString stringWithFormat:@"%@ %@", oldObject[@"firstName"], oldObject[@"lastName"]]; 
      } 
     }]; 
    } 
    if (oldSchemaVersion < 2) { 
     [migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) { 
      // give JP a dog 
      if ([newObject[@"fullName"] isEqualToString:@"JP McDonald"]) { 
       Pet *jpsDog = [[Pet alloc] initWithValue:@[@"Jimbo", @(AnimalTypeDog)]]; 
       [newObject[@"pets"] addObject:jpsDog]; 
      } 
     }]; 
    } 
    if (oldSchemaVersion < 3) { 
     [migration enumerateObjects:Pet.className block:^(RLMObject *oldObject, RLMObject *newObject) { 
      // convert type string to type enum if we have outdated Pet object 
      if (oldObject && oldObject.objectSchema[@"type"].type == RLMPropertyTypeString) { 
       newObject[@"type"] = @([Pet animalTypeForString:oldObject[@"type"]]); 
      } 
     }]; 
    } 
    NSLog(@"Migration complete."); 

它看起来像你声明中,你列举的对象和手动更新架构的模块。