2012-02-06 85 views

回答

4

核心數據要求您創建一個映射模型,以從當前版本的數據存儲轉到最新版本的數據存儲。這意味着你將需要創建一個從v1 - > v2和v2 - > v3和v1 - > v3。

從核心數據版本管理和遷移指南

Tries to find a mapping model that maps from the managed object model for the existing store to that in use by the persistent store coordinator. Core Data searches through your application’s resources for available mapping models and tests each in turn. If it cannot find a suitable mapping, Core Data returns NO and a suitable error.

Note that you must have created a suitable mapping model in order for this phase to succeed.

在本蘋果文檔 Core Data Mapping

-1

progressivelyMigrateURL是一個偉大的樣本,但我不認爲你真的需要它爲您的文檔的版本出現,只要你所以你需要爲每一次開發應用許多映射模型作爲數據模型的受支持版本的數量減去1而不是更多(例如,您不需要app1.0_to_app1.1.xcmappingmodel作爲1.1版本,不再是最新版本)。每次創建新版本時,只需在每個映射模型中更正目標模型,並在需要時再添加一個目標模型,也許您需要生成新模型並刪除舊模型。事實是,在一個階段的遷移(不會強制您創建更多的映射模型(與漸進的模型相比))在運行時會快得多,因爲您可能會注意到。 您也不需要爲微不足道的情況創建映射模型,也可以使用輕量級遷移(使用默認遷移過程,而不是在具體情況下需要映射模型,該模型不能在運行時生成(當然,您需要在您的),或藉助於在運行時創建的映射模型的幫助,藉助NSMappingModel類的inferredMappingModel:error:method:destinationModel:error:方法進行遷移,然後根據需要在代碼中進行自定義(在此情況下,您需要手動觸發遷移通過調用migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:NSMigrationManager實例的方法,據我瞭解)。 祝你好運!

相關問題