Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Realm be used as a persistence model to represent a CloudKit public database?

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.

like image 669
Matt Mac Avatar asked Feb 24 '16 19:02

Matt Mac


1 Answers

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.

like image 94
Manuel Avatar answered Nov 04 '22 22:11

Manuel