2016-01-31 71 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."); 

它看起來像你聲明中,你列舉的對象和手動更新架構的模塊。