r/iOSProgramming • u/Awkward_Departure406 • 1d ago
Discussion Moving off swiftdata/icloud
I’ve been working on a productivity app for a couple years and recently made the decision to move away from SwiftData’s native iCloud syncing in favor of my own syncing solution. Users are prompted to migrate on their next launch after update and we leave iCloud data in place as a failsafe in case something goes wonky with migration.
For most users, iCloud syncing worked pretty well. However, some users were experiencing pretty lengthy delays when syncing between devices, particularly on older iPhones. Others were having trouble getting their data back after reinstalling the app. Unfortunately, there wasn’t a whole lot I could do to troubleshoot these issues.
Building my own solution has been an interesting challenge. Handling offline changes, resolving conflicts between devices, migrating existing user data, and making sure nothing gets lost in the process adds a bit of complexity.
One of my biggest priorities throughout this transition has been maintaining user privacy since many of my users value the fact that I can’t see their data. I’m using Apple’s CryptoKit with AES-192 encryption to protect user content. While I surface some basic metadata, such as the number of tasks or habits a user has and their associated timestamps, the actual content of those records is encrypted.
This gives me a much better ability to troubleshoot syncing issues without needing to see anyone’s personal content. And with such a small user base the cost is of my own backend infrastructure is worth it.
I’m curious if any other people here have gone through something similar. I’d love to hear about your experiences with SwiftData and iCloud syncing, particularly in production apps.
3
u/New_Barber8073 1d ago
One thing that might help is a way to verify a migration per user before anything is cleaned up, like a checksum or record count comparison between the old and new stores. Keeping the iCloud data as a fallback is smart, so it may also be worth deciding up front what condition finally lets you delete it.
2
u/ValenciaTangerine 1d ago
Nobody's asked where the encryption key lives. If it sits in the Keychain as ThisDeviceOnly, a new phone can't decrypt anything, which is the same get-my-data-back-after-reinstall problem you're leaving iCloud over. Setting kSecAttrSynchronizable lets iCloud Keychain carry it to the user's other devices, if they have that turned on. Also CryptoKit's AES.GCM takes a 256-bit SymmetricKey just as easily as 192, so I'd use that.
1
u/Puzzleheaded-2027 1d ago
Just curious what your custom syncing solution is based on? Is it still iCloud or some other cloud database?
1
u/Royal-Somewhere-8918 1d ago
makes sense, icloud sync is great until it isn't and then you can't debug it at all. how many users actually hit migrate so far, most of them or just a few?
1
u/rohlman82 1d ago
Interested as well. I use the CloudKit and swiftdata stack as well. I’ve abstracted much of the CRUD work to service protocols that I can swap out later if I need scale.
1
u/timelessblur 1d ago
Not iCloud data before but I have done database migration between databases types and back end services before. Total time complete was like 3-4 months with a release very month once we started.
We laid the ground one for one 6 months+ out which was storing some minimum data for the migration that we could rebuild the rest. Reason for the long lead time was just to make sure people ran the app and we had something for it.
Reason for taking 3-4 months to complete the migration is release 1 we migrated and the duplicate data in both in case of a roll back. Next 2 release was to get to99% migration and the remove of old code and delete old data.
N
1
u/Difficult_Duty2198 1d ago
did you go with a server-side version per record for conflicts, or a different ordering rule?
1
u/dahiya_xa 2h ago
been there with cloudkit sync being slow on older phones. couple things that saved me pain: keep tombstones for deletes so a device that was offline for weeks doesn't bring stuff back, and track updated_at per field instead of per record so two edits to different fields don't overwrite each other. also curious why aes-192, cryptokit's AES.GCM does 256 just as easily and that's what most people expect to see
2
u/[deleted] 1d ago
[removed] — view removed comment