For the past while I've been testing CKSyncEngine for a reading app of mine, with two iPads on the same iCloud account and a library of about 14,000 books, and most of it behaved the way Apple's docs and the WWDC session describe. The part that didn't is what happens when the record zone your data lives in gets deleted, so these are my notes on how that deletion reaches the app, and on what went wrong when we tried to recover from it.
How a deleted zone reaches you
There are two ways the engine tells you the zone is gone. On the read path it comes as a database change, with a reason attached, and the reason decides what we do next. Only .deleted means "recreate the zone and upload again", since .purged (the user deleted the app's iCloud data) and .encryptedDataReset (the user reset their encryption keys) mean the user wants that data gone, so for those we stop syncing instead:
func handleEvent ( _ event : CKSyncEngine . Event , syncEngine : CKSyncEngine ) async { switch event { case .…