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:
Create custom zone (e.g., "TestZone1") via CKDatabase.modifyRecordZones(saving:)
Copy records to zone for sharing purposes
Delete zone using any CloudKit deletion API - returns success, no errors
Immediate verification: Zone is gone from database.allRecordZones()
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
CloudKit
RSS for tagStore structured app and user data in iCloud containers that can be shared by all users of your app using CloudKit.
Posts under CloudKit tag
189 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am using SwiftData with CloudKit to synchronize data across multiple devices, and I have encountered an issue: occasionally, abnormal sync behavior occurs between two devices (it does not happen 100% of the time—only some users have reported this problem). It seems as if synchronization between the two devices completely stops; no matter what operations are performed on one end, the other end shows no response.
After investigating, I suspect the issue might be caused by both devices simultaneously modifying the same field, which could lead to CloudKit's logic being unable to handle such conflicts and causing the sync to stall. Are there any methods to avoid or resolve this situation?
Of course, I’m not entirely sure if this is the root cause. Has anyone encountered a similar issue?
Hi,
I am implementing a premium feature in my app where CloudKit syncing is available only for "Pro" users.
The Workflow:
Free Users: I initialize the ModelContainer with cloudKitDatabase: .none so their data stays local.
Pro Upgrade: When a user purchases a subscription, I restart the container with cloudKitDatabase: .automatic to enable syncing.
The Problem:
If a user starts as "Free" (creates local data) and later upgrades to "Pro", the app crashes immediately upon launch with the following error:
Fatal error: Failed to create ModelContainer: SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer, _explanation: nil)
It seems that SwiftData fails to load the existing data once the configuration changes to expect a CloudKit-backed store.
My Question:
Is there a supported way to "toggle" CloudKit on for an existing local dataset without causing this crash? I want the user's existing local data to start syncing once they pay, but currently, it just crashes.
My code:
import Foundation
import SwiftData
public enum DataModelEnum: String {
case task, calendar
public static let container: ModelContainer = {
let isSyncEnabled = UserDefaults.isProUser
let config = ModelConfiguration(
groupContainer: .identifier("group.com.yourcompany.myApp"),
cloudKitDatabase: isSyncEnabled ? .automatic : .none
)
do {
return try ModelContainer(for: TaskModel.self, CalendarModel.self, configurations: config)
} catch {
fatalError("Failed to create ModelContainer: \(error)")
}
}()
}
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
SwiftData
When I try to archive an app in order to submit it to the App Store I receive the following errors I do not know how to fix:
error: Framework /Users/fbartolom/Library/Developer/Xcode/DerivedData/Virtual_Tags-apzduassdiglhcapscsllvzbfgid/Build/Intermediates.noindex/ArchiveIntermediates/Virtual Tags/InstallationBuildProductsLocation/Applications/VirtualTags.app/Frameworks/StoreKit.framework did not contain an Info.plist (in target 'VirtualTags' from project 'Virtual Tags') error: Framework /Users/fbartolom/Library/Developer/Xcode/DerivedData/Virtual_Tags-apzduassdiglhcapscsllvzbfgid/Build/Intermediates.noindex/ArchiveIntermediates/Virtual Tags/InstallationBuildProductsLocation/Applications/VirtualTags.app/Frameworks/Security.framework did not contain an Info.plist (in target 'VirtualTags' from project 'Virtual Tags') error: Framework /Users/fbartolom/Library/Developer/Xcode/DerivedData/Virtual_Tags-apzduassdiglhcapscsllvzbfgid/Build/Intermediates.noindex/ArchiveIntermediates/Virtual Tags/InstallationBuildProductsLocation/Applications/VirtualTags.app/Frameworks/CloudKit.framework did not contain an Info.plist (in target 'VirtualTags' from project 'Virtual Tags')
MacBook Pro M5, Tahoe 26.1, Xcode 26.1.1
Hi everyone,
I am experiencing an iCloud provisioning problem I cannot resolve, and Developer Support has not been able to help.
My App ID:
com.exaqservices.ArkyvTiles
Symptoms:
1. In Xcode (v16.2), enabling iCloud in Signing & Capabilities repeatedly fails with:
The app ID does not include the iCloud container. Click Try Again.
Clicking Try Again does nothing. The error persists forever.
2. In Certificates, Identifiers & Profiles:
• The iCloud capability is enabled for this App ID.
• The CloudKit container is selected.
• But the portal no longer shows the “iCloud Documents” checkbox, which used to be required for ubiquitous document support.
3. Xcode cannot regenerate provisioning profiles because it claims the App ID is missing the iCloud container — even though the container is attached.
4. Provisioning profiles on the Apple Developer site all appear expired, and new ones do not generate correctly.
5. The App Store Connect interface also does not show an iCloud Services section under App Information → Capabilities as older guides describe.
Expected Behavior:
Since iCloud and the CloudKit container are enabled on the App ID, Xcode should successfully enable:
• com.apple.developer.icloud-services
• com.apple.developer.icloud-container-identifiers
• com.apple.developer.ubiquity-container-identifiers (if needed)
• com.apple.developer.ubiquity-kvstore-identifier
Instead, the entitlements never propagate.
What I suspect:
This seems like an App ID metadata mismatch or a stale backend entry where:
• the CloudKit container is attached but the entitlement isn’t linked,
• the “iCloud Documents” flag is missing due to a UI transition,
• provisioning profiles cannot be regenerated because the App ID is not updating correctly.
What I need help with:
Can someone from Apple engineering confirm:
• Whether my App ID metadata is corrupted,
• If entitlements need to be manually refreshed,
• Or if the “iCloud Documents” toggle has moved or is no longer exposed?
This is blocking development completely — I cannot build, sign, or deploy the app with iCloud.
Thank you!
Alan Metzger
Hi
Given a simple multiplatform app about Mushrooms, stored in SwiftData, hosted in iCloud using a TextEditor
@Model
final class Champignon: Codable {
var nom: String = ""
../..
@Attribute(.externalStorage)
var attributedStringData: Data = Data()
var attributedString: AttributedString {
get {
do {
return try JSONDecoder().decode(AttributedString.self,
from: attributedStringData)
} catch {
return AttributedString("Failed to decode AttributedString: \(error)")
}
}
set {
do {
self.attributedStringData = try JSONEncoder().encode(newValue)
} catch {
print("Failed to encode AttributedString: \(error)")
}
}
}
../..
Computed attributedString is used in a TextEditor
private var textEditorView: some View {
Section {
TextEditor(text: $model.attributedString)
} header: {
HStack {
Text("TextEditor".localizedUppercase)
.foregroundStyle(.secondary)
Spacer()
}
}
}
Plain Text encode, decode and sync like a charm through iOS and macOS
Use of "FontAttributes" (Bold, Italic, …) works the same
But use of "ForegroundColorAttributes" trigger an error :
Failed to decode AttributedString: dataCorrupted(Swift.DecodingError.Context(codingPath: [_CodingKey(stringValue: "Index 3", intValue: 3), AttributeKey(stringValue: "SwiftUI.ForegroundColor", intValue: nil), CodableBoxCodingKeys(stringValue: "value", intValue: 1)], debugDescription: "Platform color is not available on this platform", underlyingError: nil))
Is there a way to encode/decode attributedString data platform conditionally ?
Or another approach ?
Thanks for advices
We are currently implementing a custom iCloud sync for our macOS and iOS apps using CloudKit. Syncing works fine as long as the number of record sends is relatively small.
But when we test with a large number of changes ( 80,000+ CKRecords ) we start running into problems.
Our sending strategy is very conservative to avoid rate limits:
We send records sequentially in batches of 250 records
With about 2 seconds pause between operations
Records are small and contain no assets (assets are uploaded separately)
At some point we start receiving:
“Database commit size exceeds limit”
After that, CloudKit begins returning rate-limit errors with retryAfter-Information in the error.
We wait for the retry time and try again, but from this moment on, nothing progresses anymore. Every subsequent attempt fails.
We could not find anything in the official documentation regarding such a “commit size” limit or what triggers this failure state.
So my questions are:
Are there undocumented limits on the total number of records that can exist in an iCloud database (private or shared)?
Is there a maximum volume of record modifications a container can accept within a certain timeframe, even if operations are split into small batches with pauses?
Is it possible that sending large numbers of records in a row can temporarily or permanently “stall” a CloudKit container?
Any insights or experiences would be greatly appreciated.
Thank you!
I am trying to use Zone Sharing in my SwiftUI app. I have been attempting to get the UICloudSharingController to show an initial share screen to pick users and the mechanism to send the invitation.
From the documentation, it appears that the UICloudSharingController .init(preparationHandler:) API is deprecated so I am not using that approach. Following the Apple documentation, I am creating a Zone Share and NOT saving it and presenting using the UICloudSharingController(share:container:) API. However, this presents a UI that is the 'mgmt' API for a Share. I can get to the UI I was expecting by tapping on the 'Share with More People' option, but I want to start on that screen for the user when they have not shared this before.
So, I found an example app from Apple at: https://github.com/apple/sample-cloudkit-zonesharing. It has the same behavior. So we can simply discuss this problem based on that example code.
How do I get the next View presented when tapping 'Share Group' to be the invitation for new users screen?
Here is the UI it presents initially:
And here is the UI (on the bottom half of the screen) I am trying to start the share process with:
Thanks,
Charlie
I have an app for macOS that is built using Mac Catalyst. I need to perform some background processing. I'm using BGProcessingTaskRequest to schedule the request. I have also integrated CKSyncEngine so I need that to be able to perform its normal background processing.
On iOS, when the user leaves the app, I can see a log message that the request was scheduled and a bit later I see log messages coming from the actual background task code.
On macOS I ran the app from Xcode. I then quit the app (Cmd-q). I can see the log message that the request was scheduled. But the actual task is never run. In my test, I ran my app on a MacBook Pro running macOS 26.0. When I quit the app, I checked the log file in the app sandbox and saw the message that the task was scheduled. About 20 minutes later I closed the lid on the MacBook Pro for the night. I did not power down, it just went to sleep. Roughly 10 hours later I opened the lid on the MacBook Pro, logged in, and checked the log file. It had not been updated since quitting the app. I should also mention that the laptop was not plugged in at all during this period.
My question is, does a Mac Catalyst app support background processing after the user quits the app? If so, how is it enabled?
The documentation for BGProcessingTaskRequest and BGProcessingTask show they are supported under Mac Catalyst, but I couldn't find any documentation in the Background Tasks section that mentioned anything specific to setup for Mac Catalyst.
Running the Settings app and going to General -> Login Items & Extension, I do not see my app under the App Background Activity section. Does it need to be listed there? If so, what steps are needed to get it there?
If this is all documented somewhere, I'd appreciate a link since I was not able to find anything specific to making this work under Mac Catalyst.
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
CloudKit
macOS
Mac Catalyst
Background Tasks
it seems that is going to the appstore to find the app to execute the share but my app is not in the appstore yet. I am using a sandboxed user and a non sandboxed user, I have tried real phones connected to xcode and simulator same effect, looking for how to test my ckshare in testflight thanks
Hello,
If I want to modify records in my public database, this works fine. However, if I change from public to private in the requesturl, I get the response: "500 - Internal Error".
According to the CK WebService Reference, it is possible to access the private database.
Could someone explain to me if it is really an internal error and if it could be fixed by Apple, since I would like to access my own private database with the server-to-server key.
Thanks in advance.
Hi all...
The app I'm building is not really a beginner level test app, it's intended to be published so I want everything to be done properly while I'm both learning and building the app. I'm new to swift ecosystem but well experienced with python and JS ecosystems.
These two models are causing my app to crash
@Model
final class CustomerModel {
var id: String = UUID().uuidString
var name: String = ""
var email: String = ""
var phone: String = ""
var address: String = ""
var city: String = ""
var postalCode: String = ""
var country: String = ""
@Relationship(deleteRule: .nullify)
var orders: [OrderModel]?
@Relationship(deleteRule: .nullify)
var invoices: [InvoiceModel]?
init() {}
}
@Model
final class OrderModel {
var id: String = UUID().uuidString
var total: Double = 0
var status: String = "processing"
var tracking_id: String = ""
var order_date: Date = Date.now
var updated: Date = Date.now
var delivery_date: Date?
var active: Bool = true
var createdAt: Date = Date.now
var items: [OrderItem]?
@Relationship(deleteRule: .nullify)
var invoice: InvoiceModel?
@Relationship(deleteRule: .nullify)
var customer: CustomerModel?
init() {}
}
both referenced in this model:
@Model
final class InvoiceModel{
var id: String = UUID().uuidString
var status: String = "Pending"
var comment: String = ""
var dueDate: Date = Date.now
var createdAt: Date = Date.now
var updated: Date = Date.now
var amount: Double = 0.0
var paymentTerms: String = "Once"
var paymentMethod: String = ""
var paymentDates: [Date] = []
var numOfPayments: Int = 1
@Relationship(deleteRule: .nullify, inverse: \OrderModel.invoice)
var order: OrderModel?
@Relationship(deleteRule: .nullify)
var customer: CustomerModel?
init() {}
}
This is my modelContainer in my index structure:
@main
struct Aje: App {
var appContainer: ModelContainer = {
let schema = Schema([UserModel.self, TaskModel.self, SubtaskModel.self, InventoryModel.self, SupplierModel.self])
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false, allowsSave: true, groupContainer: .automatic, cloudKitDatabase: .automatic)
do{
return try ModelContainer(for: schema, configurations: [config])
}catch{
fatalError("An error has occured: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(appContainer)
}
}
This works fine but the below after adding the problematic models crashes the app unless CloudKit is disabled
@main
struct Aje: App {
var appContainer: ModelContainer = {
let schema = Schema([UserModel.self, TaskModel.self, SubtaskModel.self, InventoryModel.self, SupplierModel.self, InvoiceModel.self, OrderModel.self, CustomerModel.self])
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false, allowsSave: true, groupContainer: .automatic, cloudKitDatabase: .automatic)
do{
return try ModelContainer(for: schema, configurations: [config])
}catch{
fatalError("An error has occured: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(appContainer)
}
}
Topic:
Developer Tools & Services
SubTopic:
Xcode Cloud
Tags:
Swift Packages
CloudKit
SwiftUI
SwiftData
I have been using the basic NSPersistentContainer with 100k+ records for a while now with no issues. The database size can fluctuate a bit but on average it takes up about 22mb on device.
When I switch the container to NSPersistentCloudKitContainer, I see a massive increase in size to ~150mb initially. As the sync engine uploads records to iCloud it has ballooned to over 600mb on device. On top of that, the user's iCloud usage in settings reports that it takes up 1.7gb in the cloud.
I understand new tables are added and history tracking is enabled but the size increase seems a bit drastic. I'm not sure how we got from 22mb to 1.7gb with the exact same data.
A few other things that are important to note:
I import all the 100k+ records at once when testing the different containers. At the time of the initial import there is only 1 relation (an import group record) that all the records are attached to.
I save the background context only once after all the records and the import group have been made and added to the context.
After the initial import, some of these records may have a few new relations added to them over time. I suppose this could be causing some of the size increase, but its only about 20,000 records that are updated.
None of the records include files/ large binary data.
Most of the attributes are encrypted.
I'm syncing to the dev iCloud environment.
When I do make a change to a single attribute in a record, CloudKit reports that every attribute has been modified (not sure if this is normal or not )
Also, When syncing to a new device, the sync can take hours - days. I'm guessing it's having to sync both the new records and the changes, but it exponentially gets slower as more records are downloaded. The console will show syncing activity, but new records are being added at a slower rate as more records are added. After about 50k records, it grinds to a halt and while the console still shows sync activity, only about 100 records are added every hour.
All this to say i'm very confused where these issues are coming from. I'm sure its a combination of how i've setup my code and the vast record count, record history, etc.
If anyone has any ideas it would be much appreciated.
I have SwiftData models containing arrays of Codable structs that worked fine before adding CloudKit capability. I believe they are the reason I started seeing errors after enabling CloudKit.
Example model:
@Model
final class ProtocolMedication {
var times: [SchedulingTime] = [] // SchedulingTime is Codable
// other properties...
}
After enabling CloudKit, I get this error logged to the console:
'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
CloudKit Console shows this times data as "plain text" instead of "bplist" format.
Other struct/enum properties display correctly (I think) as "bplist" in CloudKit Console.
The local SwiftData storage handled these arrays fine - this issue only appeared with CloudKit integration.
What's the recommended approach for storing arrays of Codable structs in SwiftData models that sync with CloudKit?
In didFinishLaunchingWithOptions I have this setup for getting the token to send to my server for notifications. The issue is that the delegate callback didRegisterForRemoteNotificationsWithDeviceToken gets called twice when also initializing a CKSyncEngine object.
This confuses me. Is this expected behavior? Why is the delegate callback only called twice when both are called, but not at all when only using CKSyncEngine.
See code and comments below.
/// Calling just this triggers `didRegisterForRemoteNotificationsWithDeviceToken` once.
UIApplication.shared.registerForRemoteNotifications()
/// When triggering the above function plus initializing a CKSyncEngine, `didRegisterForRemoteNotificationsWithDeviceToken` gets called twice.
/// This somewhat make sense, because CloudKit likely also registers for remote notifications itself, but why is the delegate not triggered when *only* initializing CKSyncEngine and removing the `registerForRemoteNotifications` call above?
let syncManager = SyncManager()
/// Further more, if calling `registerForRemoteNotifications` with a delay instead of directly, the delegate is only called once, as expected. For some reason, the delegate is only triggered when two entities call `registerForRemoteNotifications` at the same time?
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
UIApplication.shared.registerForRemoteNotifications()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("didRegisterForRemoteNotificationsWithDeviceToken")
}
My app has three main SwiftData models: Collection, SavedItem, and Extract.
A Collection can contain subcollections (folders within folders) and SavedItems (files).
Each SavedItem can have child Extracts.
I'm preparing for the ability for users to be able to share Collections with each other.
Currently, my architecture treats each Collection as the root of its own CloudKit zone (a root parent Collection and all of its items and subcollections live in 1 zone).
This makes sharing and isolation straightforward, but it also means that moving a SavedItem or subcollection between Collections involves moving it across zones.
I’m trying to figure out the best pattern for handling these cross-zone moves while keeping data integrity, relationships, and sharing intact.
My understanding is that in CloudKit, and moving a record from Zone A to Zone B would require deleting it from Zone A and recreating it in Zone B - while somehow maintaining the link back to my local SwiftData store.
Has anyone run into this or know how best I should handle it?
Hi, I'm using SwiftData in my app, and I want to sent data to iCloud with CloudKit, but I found that If the user turns off my App iCloud sync function in the settings App, the local data will also be deleted.
A better way is maintaining the local data, just don't connect to iCloud.How should I do that?
I need guidance!!! I'm just getting started with CloudKit
And I would be appreciated!
i want to save data like images, text,amd mapviews with swiftui. It is only saved but if you delete the app of buy a new iPhone everything is deleted, how can I make if that the information saved on my app is saved even after I update the app, delete the app, or put the app in another iPhone with SwiftUI? i have watched youtube videos and im still confused,please help.
The CloudKit Console includes a Unique Users table in the Usage section.
The numbers here are lower than what I would expect. Does this only track a certain percentage of users, e.g. users have opted in to share analytics with developers?
I a using the current RC version of iOS on both my iPhone and iPad. I and developing an iCloud based app and it works correctly on iOS 18. When I upgraded to iOS 26 the iCloud functions work correctly but the push notifications do not work.
The issue appears to be creating subscriptions. The following code should create a subscription and does not get an error, but it did to create a subscription under iOS 26.
func subscribeToNotifications(recordType: String,
subscriptionID: String, notification: CKSubscription.NotificationInfo) {
let subscriptionIDForType = "\(subscriptionID)-\(recordType)"
let predicate = NSPredicate(value: true)
let subscription = CKQuerySubscription(recordType: recordType, predicate: predicate, subscriptionID: subscriptionIDForType, options: [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion])
let notification = CKSubscription.NotificationInfo()
subscription.notificationInfo = notification
CKContainer.default().publicCloudDatabase.save(subscription) { (returnedSubscription, error) in
if let error = error {
print("Error saving subscription: \(error)")
} else {
print("Successfully saved subscription: recordType: " + recordType + " subscriptionID: " + subscriptionIDForType)
}
}
}
Print results:
Successfully saved subscription: recordType: folder subscriptionID: folderName-folder
Topic:
App & System Services
SubTopic:
Notifications
Tags:
CloudKit
User Notifications
iPad and iOS apps on visionOS
UIKit