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

I would like to use Realm as a persistence model to represent my public CloudKit database. Is it possible?

In particular, I would like to use CloudKit to take the Realm data model and store it in my CloudKit database.

This would overcome my current problem: get data from CloudKit every time the application is loaded into memory. Without a local data model, when there is no Internet connection, data is not retrieved due to a lack of persistence.

If the application is deleted from memory, any data stored in the application retrieved from CloudKit is also deleted from memory.

+5
source share
2 answers

In my opinion, if you want to use CloudKit, you should use Core Data as permanent storage. It works great together.

If you prefer modern solutions, try the Realm Mobile Platform https://realm.io/products/realm-mobile-platform/

Alternatively, you can try writing some custom backend with Vapor and use Realm as a permanent storage.

0
source

You may just need to write code to convert your model objects to / from CKRecords, which can be sent to CloudKit.

If you tried to use a private database, I would suggest using this library, which is compatible with both Realm and Core Data (disclaimer, I am the author): https://github.com/mentrena/SyncKit

Another solution for Core Data is https://github.com/nofelmahmood/Seam

However, the public database does not allow you to request changes, so you will have to deploy your own implementation to save the cache of some write request, and not the fully synchronized local cache of the whole model.

0
source

Source: https://habr.com/ru/post/1243787/


All Articles