I have a travel planner app I’m working on that uses Core Data. 2 of my entities (Person and Trip) have a many-to-many relationship (one person may go on many trips, and a single trip includes many people). I would like to give the user the opportunity to create an external backup file of their data as a txt file that can either live in iCloud, or a location in Files. I will need to be able to serialize and deserialize for backup and restore operations.
From what I’ve read it seems that JSON can only do one-to-many relationships (strictly hierarchical), not many-to-many. If I’m mistaken and it can indeed to many-to-many, can someone help me understand how to serialize that?
But if in fact it cannot, what other methods would be recommended for backing up Core Data into a txt file?
Is there a specific reason to make it into a text file, vs syncing to iCloud itself?
I am already syncing to iCloud with CloudKit, but to answer your question, yes, I want to allow an external backup to a file in order to allow the user to be able to import into an app on a different account, or potentially in the future import into a different app altogether, or on a different platform. The last 2 are possible future features and not important now, but for now I would like to be able to have 2 people on different iCloud accounts be able to share their data.
It doesn’t necessarily have to be a text file. but I’d rather stay away from binaries if possible for future cross-platform considerations.
You could export the data to SQLite, or because it’s core data possibly access the SQLite directly and export that?
That could work for the present (creating a backup and reloading it when needed). Not sure how/if Core Data stored on top of a SQLite schema would be usable cross-platform, but I can deal with that later.