Eduhalfen
Eduhalfen

Reputation: 3

Core Data location file

Few years ago, I wrote an app using Core Data in Objective-C. The file.sqlite was saved on folder Documents. I would like to write an update version but in swift language and I am care about the users don't loose their saved records. I saw that the new file.sqlite is saved on folder Application Support. I have 2 questions:

is it possible to save on the same folder that the users don't loose the records?

Or is it possible to copy the old file.sqlite to Application Support that the users can update the old records?

Upvotes: 0

Views: 265

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70976

You can put the persistent store file in any directory that your app can write to. Core Data has no rules about where these files have to go. If you want to use the documents folder, just use the documents folder.

If you're using NSPersistentContainer, you can change the default location by using an instance of NSPersistentStoreDescription. If you're not using NSPersistentContainer, use a file URL that points to your desired location when you call addPersistentStoreWithType:configuration:URL:options:error:.

Upvotes: 1

Related Questions