I followed an article in raywanderlich.com but it uses email for import and export.
I actually implemented export by zipping my .sqlite file and renaming the extension of the file with .abc ( use extension unique to your app ). By this way user doesn't knows the extension, so the chances of getting corrupted by editing this file may be low. And for the import i just unzip the file and replace the existing model. Note here i just replace my existing data with the imported file. I have used it in one app. And no complaints. People rarely edit if the extension is unknown.
Regarding Older data model, AFAIK if you have handled the core data migration, then the old model should be migrated to new model.
Regarding validating the file during the import, I think you cannot validate the .sqlite file? I mean to validate, you need to open the .sqlite file and read it, and to read it, it must match the schema. If it is corrupted it will not match and the app will crash. All you can do is catch the exception and throw error message.
Another ways
- Rename the .sqlite file to something like .db so user may not try to open it with any .sqlite viewer.
- Export as xml or json. By this way you can validate the import file and it will be easy if you are not just replacing the existing data during the import.
Pros
1. Simple way, you don't need any zipping library or any extra methods for converting to and from xml or json.
Cons
- And if you are not just replacing the existing data during the import, then you got to do a lot. You have to copy all the entities from this .sqlite to another one. In that case i would be simply emport the data to json and rename the file extension. During the import i just parse the json and create / update managed object context. In this json case i would be creating UUID to uniquely identify each record.
Core data generated .sqlite is not the normal .sqlite file so the user will have some surprises if he tries to open it with sqllite viewer.
Once the file the goes out of app. We cannot control how it is being used. All we can do is throw some error message, if the user imports the corrupted file.
hope this helps.