Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync old changes, not only updates #84

Closed
bitomule opened this issue Aug 26, 2018 · 5 comments
Closed

Sync old changes, not only updates #84

bitomule opened this issue Aug 26, 2018 · 5 comments

Comments

@bitomule
Copy link
Contributor

Expected behavior

Sync existing realm data to CloudKit.

Actual behavior(optional)

Objects present in the database before adding Icecream doesn´t sync.

Steps to reproduce the problem(optional)

Create a realm database without Icecream, add and setup Icrecream to your project. Only updates are pushed to the cloud.

@dbmrq
Copy link
Contributor

dbmrq commented Oct 8, 2018

While this isn't implemented, I think it's useful to mention here that we can use syncRecordsToCloudKit, as suggested here.

In my case, for my Note and Quote objects, I'm doing this after starting the sync engine:

let realm = try! Realm()
var recordsToStore: [CKRecord] = []
recordsToStore += realm.objects(Note.self).map { $0.record }
recordsToStore += realm.objects(Quote.self).map { $0.record }
syncEngine?.syncRecordsToCloudKit(recordsToStore: recordsToStore, recordIDsToDelete: [])

It seems to be working pretty well.

@caiyue1993
Copy link
Owner

Hi @bitomule @dbmrq ,

I've made a PR #94 regarding this issue. I added a public method named pushAll to SyncEngine. You may call that method to push all local existing Realm data to CloudKit manually. So you don't have the need the write the code yourself @dbmrq 😊.

However, we should NOT call pushAll too frequently only when necessary.

@dbmrq
Copy link
Contributor

dbmrq commented Oct 19, 2018

Awesome, thank you!

One more thing: how about fetching all CloudKit data for the first time? E.g., I have some data from my iPhone and then buy a new iPad and install the app… it needs to get all CloudKit data, not just the changes. Is there something like a pullAll method to do that? Or is it already handled automatically?

@caiyue1993
Copy link
Owner

caiyue1993 commented Oct 19, 2018

@dbmrq Absolutely, "fetching all CloudKit data for the first time" is already been handled. Actually we've provided a pull method(not pullAll), but normally you don't need to call that because it's invoked automatically every time SyncEngine gets initialized.

For details, I suggest you read the source code and check CloudKit docs for more mechanism.

@dbmrq
Copy link
Contributor

dbmrq commented Oct 19, 2018

Fantastic, thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants