Many say it is impossible, or simply not worth the effort. Many have tried and failed. Many people along the path have simply offered the unhelpful advice: "Use CoreData". The more recent refrain has become "Use SwiftData".
First off, I don't want to use CoreData or SwiftData. Yes, I've tried before and they've polluted my code base. The CoreData schema GUI modeling is a pain and not easily git-commitable. Migrating to a code-based model is likewise frustrating due to all of the boilerplate. The context is practically global state which makes architecture an exercise in swimming upstream. The code is not functional, it's fully and unapologetically OOP. Which makes it hard to test. It performs dark art technical magical rituals behind the scenes so validating behavior is nigh impossible.
SwiftData suffers from different problems. Opaque errors (caused by insane macros), are pure pain to deal with. Sometimes the project fails to build with even innocuous mistakes (like accessing a nested type in a `#Predicate`). Limitations on schema data makes me question what happened to initializers (does everything really have to be optional or have a default value). And the very worst of all? SwiftData is so opinionated via use of `#Predicate` that it becomes absolutely unusable for larger queries.
There's other issues of course - when tied into Apple's ecosystem your data (arguably your most valuable asset) is vendor-locked.
I've had to shelve several projects simply because I started down the path of using Apple's persistence frameworks. Not because I couldn't - I've used CoreData extensively at my job and personal projects, but rather, because I didn't want to.
Instead, here's my wish-list:
1. Local, self-made SQLite database on device
2. Transaction files that sync via iCloud
3. Merged SQLite transactions on all iCloud-connected devices
4. The possibility to sync files with a proprietary server
If you have any suggestions, please feel free to [let me know](mailto:
[email protected])!