Core Data Migration: How to delete the Core Data stack?

后端 未结 2 2062
忘掉有多难
忘掉有多难 2021-02-13 21:50

My plan is to delete the old Core Data stack (the NSManagedObjectModel .momd file & the NSPersistentStore .sqlite file) b

2条回答
  •  遇见更好的自我
    2021-02-13 22:28

    If you create a blank Core Data application you find the necessary code in Apples comments in the Application Delegate:

    If you encounter schema incompatibility errors during development, you can reduce their frequency by:

    • Simply deleting the existing store: [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

    • Performing automatic lightweight migration by passing the following dictionary as the options parameter:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

提交回复
热议问题