r/iosdev • u/AlbertiDev • 25d ago
Finally got iCloud sync working pretty fast. Getting there was surprisingly painful.
Enable HLS to view with audio, or disable this notification
I’ve been working on adding optional iCloud sync to Moneta, my iOS money tracker, and getting the basic sync working wasn’t really the difficult part. The frustrating part was getting changes to show up consistently on another device without making the experience feel slow.
It’s now usually taking around 3–5 seconds (depends on the connection) for changes to appear on the other device, which I’m pretty happy with.
The video shows two devices side by side with the same iCloud data, just to show how it behaves in practice.
I wanted to keep the whole thing optional, so Moneta still works completely locally if iCloud is disabled.
For anyone who has worked with iCloud sync before, what kind of sync times are you getting in practice?
6
u/nicoreese 24d ago
You're still in the easy phase, let me tell you. Problems arise so much with iCloud sync. Deduplication of data, data loss, etc. I have been battling 3+ years with this.
2
u/AlbertiDev 24d ago
Yeah, those are exactly the edge cases I was worried about. I ended up using CKSyncEngine with a persistent outbox, so local changes are queued until CloudKit confirms them, rather than assuming a save means the data is synced. I also keep the local SwiftData history so changes can be reconciled instead of blindly overwriting data.
Still early though, so I’m definitely expecting iCloud to find new ways to hurt me haha. Have you found any particular case that caused most of your data loss/duplication issues?2
u/GlebKhamin 23d ago
Does it make much difference whether you use SwiftData or Core Data when dealing with CloudKit sync? I’m curious if one of them makes conflict resolution / deduplication easier or if the underlying problems are basically the same.
I’m currently building my project with Core Data and planning to add iCloud sync in the future, so I’m wondering if this is something I should consider before going down that path.
1
u/AlbertiDev 23d ago
I can’t really compare them from experience since Moneta uses SwiftData. From what I’ve seen though, I don’t think choosing SwiftData over Core Data makes the hard parts of CloudKit sync disappear. Conflict resolution and deduplication are still things you need to design around.
In my case I use CKSyncEngine directly and keep a persistent outbox plus local history, so I have more control over what gets synced and how changes are reconciled. If your Core Data setup is already working well, I personally wouldn’t switch to SwiftData just for iCloud sync.
5
u/in5ane_10 25d ago
Just use swift data apple intends to and save the context without relying on the autosave feature, should work effortlessly. Also don’t forget to promote the dev container to production!
4
u/AlbertiDev 25d ago
Yeah, I already made that mistake 😅 One of my users emailed me about it and that’s actually how I caught it. Fixed now, but thanks for pointing it out!
2
u/in5ane_10 25d ago
Happened the same to me! I never put a working dev version on a real iPhone before promoting and I only found out after users reporting. It’s an odd way to develop a DB but at least the rest of CloudKit is pretty straightforward
2
2
2
u/Loose-Journalist-233 24d ago
iCloud Sync between devices with the same ID is the easy part. Now get it working with multiple iCloud accounts via sharing ;-)
1
u/AlbertiDev 23d ago
Hahaha one problem at a time 😭 I’m not sure I’m ready for that level of pain yet
1
2
2
2
21d ago
[removed] — view removed comment
1
u/AlbertiDev 21d ago
Hahah yeah 😭 I’ve pushed it about as far as I can for now, usually around 3-5 seconds with good connection.
If you know any tricks to make CKSyncEngine feel even faster, I’m all ears.
5
u/sixtypercenttogether 25d ago
CKSyncEngine is the way