![]() Import CoreData import Foundation /// Safely copies the specified `NSPersistentStore` to a temporary file. Use this new persistent store coordinator to migrate to the target URL.ĭrop all reference to the migrate-only coordinator. ![]() (As far as I can tell, having two persistent stores that work on the same database file is not a problem.) This will create a fresh NSPersistentStore instance. I followed the strategy laid out by Tom Harrington in a Stack Overflow answer:Ĭreate a new migrate-only NSPersistentStoreCoordinator and add the original store file. Since the goal is to not affect the source store (the active Core Data stack should remain usable), we’ll have to create a throwaway NSPersistentStore instance whose only purpose is to act as the source store for the copy operation. I found using it not very easy, though, mainly because of this note in the documentation:Īfter invocation of this method, the specified store is removed from the coordinator thus store is no longer a useful reference. I don’t know if Apple has official sample code for this task, but NSPersistentStoreCoordinator.migratePersistentStore(_:to:options:withType:) seems to be the right method. You should use official Core Data APIs to make copies of your database. Making a copy of the database file while a transaction is in progress can result in a corrupt copy.There are multiple files to contend with: the main database file, the write-ahead log (ending in -wal), and the shared memory file (ending in -shm).for a backup) of a SQLite database file while it’s being used by Core Data is not trivial:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |