Core Data 遷移與版本管理

  • 對數據模型進行版本管理
  • 數據遷移:不一樣版本數據模型之間進行轉換的機制
  • 輕量級遷移
  • 標準遷移

1. 關於數據模型app

  • 數據模型會被編譯
    •   .xcdatamodel文件會編譯成一種新的文件,其擴展名爲.mom,它表示Managed Object Model。
  • 數據模型能夠擁有多個版本
  • 建立新數據模型
    •   選中模型--》點擊Editor菜單--》選擇Add Model Version

2. 遷移spa

  • 輕量遷移
    •   用於相對簡單的數據模型修改。(如簡單的添加或移除實體中的屬性,或添加移除實體)。
    • // 在設置持久化存儲助手的時候進行一些修改
      if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]){}
      // 替換爲
      NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES,NSInferMappingModelAutomaticallyOption:@YES};
      if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]){}

       

  • 標準遷移
    •   標準遷移包含建立映射模型,甚至須要編寫代碼來告訴Core Data如何將數據從舊的持久化存儲移動到新的版本。
相關文章
相關標籤/搜索