Question

I'm working on a project that requires the Core Data database to be backed up somehow so that the data won't be lost if user deletes and re-downloads the app.

In the iOS storage guideline it states:

Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.

I wonder whether it means that if I put my Core Data sqlite database in the /Documents directory, it will get backed up automatically by iCloud?

If not, is there any simple solution for backing up the Core Data database? I just need the database to be recoverable after app being removed and re-installed. Syncing between devices isn't my aim here.

Was it helpful?

Solution

Yes, putting your database in the Documents directory will do exactly what you want: allow back up to iCloud without syncing to iCloud.

Syncing requires moving to the ubiquity container, but thats not what you want.

More information can be found in the Apple Technical Note which explains how to exclude a file from backup. Of course, for the backup to work, the user has to have set up their device to back up to iCloud.

Edit: Here is another helpful link: Apple's App Backup Best Practices section of the iOS App Programming Guide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top