CloudKit CKRecordZone Deletion Issue

CloudKit CKRecordZone Deletion Issue

Problem: CloudKit record zones deleted via CKDatabase.modifyRecordZones(deleting:) or CKModifyRecordZonesOperation are successfully removed but then reappear. I suspect they are automatically reinstated by CloudKit sync, despite successful deletion confirmation.

Environment:

  • SwiftData with CloudKit integration
  • Custom CloudKit zones created for legacy zone-based sharing

Observed Behavior:

  1. Create custom zone (e.g., "TestZone1") via CKDatabase.modifyRecordZones(saving:)
  2. Copy records to zone for sharing purposes
  3. Delete zone using any CloudKit deletion API - returns success, no errors
  4. Immediate verification: Zone is gone from database.allRecordZones()
  5. After SwiftData/CloudKit sync or app restart: Zone reappears

Reproduction:

  • Tested with three different deletion methods - all exhibit same behaviour:
    • modifyRecordZones(deleting:) async API
    • CKModifyRecordZonesOperation (fire-and-forget)
    • CKModifyRecordZonesOperation with result callbacks
  • Zone deletion succeeds, change tokens (used to track updates to shared records) cleaned up
  • But zones are restored presumably by CloudKit background sync

Expected: Deleted zones should remain deleted Actual: Zones are reinstated, creating orphaned zones

You would need to mark the zone as user-purged for the DefaultStore to obey an out of band delete. Alternatively you can use NSPersistentCloudKitContainer to manage CloudKit sync on the side through Coexistence and use its purge APIs.

CloudKit CKRecordZone Deletion Issue
 
 
Q