I'd like to use Realm as a persistence model to represent my CloudKit public database. Is this possible?
Specifically, I would like to use CloudKit to take a Realm data model and store it in my CloudKit public database.
This would overcome my current issue of having to fetch data from CloudKit every time the app is loaded in to memory. Without a local data model, when there is no internet connection, no data is fetched because there is no persistence.
If the app is removed from memory, any data held in the app that was fetched from CloudKit is also removed from memory.
It is possible, you just will have to write the code to convert your model objects to/from CKRecords that can be sent to CloudKit.
If you were trying to use the private database, I would suggest using this library, which is compatible with both Realm and Core Data (disclaimer, I'm the author): https://github.com/mentrena/SyncKit
Another solution, for Core Data, is https://github.com/nofelmahmood/Seam
However, the public database doesn't allow to query for changes, so you would have to roll out your own implementation to keep a cache of some record query, rather than a fully synchronized local cache of your whole model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With