Migrate Objective-C Core Data to Swift Persistent Container

192 Views Asked by At

When Apple added the new PersistentContainer class, they changed the location of the data stores. That means that if you add a new PersistentContainer, it won't pick up the current database but create one. The underlying issue is that the new store is inside another folder. How can I specify the folder for a PersistentContainer so that it picks up the old store?

1

There are 1 best solutions below

0
On

The persistent store(s) of a NSPersistentContainer are specified in its persistentStoreDescriptions array property. By default, it contains one persistent store of type SQLite, backed by a file in the Application Support folder of your app's container.

The procedure to change this is explained in the Discussion section of the documentation of this property.

The path to the file of this store is specified in the url property of the that NSPersistentStoreDescription, which is mutable. So you should set the url property of that single NSPersistentStoreDescription in that array to your desired path.