Search results for

“NSPersistentCloudKitContainer”

601 results found

Post

Replies

Boosts

Views

Activity

Core Data Migration Strategy: store relocation, schema changes and CloudKit adoption in a single release?
I am planning a Core Data migration for a macOS app targeting macOS 12 and later and I would appreciate guidance on structuring the rollout to minimise risk. Context The app currently uses a SQLite store located at: ~/Library/Containers/com.company.AppName/Data/Library/Application Support/AppName I want to: Relocate the persistent store to an app group container: ~/Library/Group Containers/group.com.company.AppName Perform schema migration, including: Renaming attributes Deleting attributes Using a custom NSEntityMigrationPolicy subclass Adopt iCloud sync using NSPersistentCloudKitContainer Potentially leverage staged migration (macOS 14+) Additionally, I intend to port the app to iOS, so the end state needs to support an app group container and CloudKit with the latest schema from the outset. Questions Store relocation vs schema migration Is it advisable to perform store relocation and schema migration in a single step, or should these be separate releases? If combined, are there pitfalls when movin
3
0
91
2d
Reply to Core Data Migration Strategy: store relocation, schema changes and CloudKit adoption in a single release?
Given that you'd move the Core Data store to a group container, I'd assume that the store will be shared across different processes, such as your main app and its extension (a widget, for example). In that case, I'd like to start with pointing you the following threads: Core Data Light Migration Crash When Widget is Installed (Error 134100). CoreData error=134100 Failed to open the store. These threads made it clear that: After a user installed your new version app, depending on what extension you have, the app and extension can open and migrate the store simultaneously, and so you will need to implement a mechanism to make sure that the store is only migrated once. Consider having your main app in charge of the the synchronization, as discussed in Avoid synchronizing a store with multiple persistent containers. Now to your questions: Store relocation vs schema migration Is it advisable to perform store relocation and schema migration in a single step, or should these be separate releases? If combined, are th
5d
Reply to CoreData + CloudKit -- Many-to-Many Relationship not Syncing
This sounds like a general synchronization issue, and so you can probably start with the technotes mentioned in this post to hopefully figure out the cause of the issue. NSPersistentCloudKitContainer supports many-to-many relationships. Before seeing an evidence that proves it doesn't work (by going through the debugging process the technotes describe), I probably won't change the Core Data model. Best, —— Ziqiao Chen  Worldwide Developer Relations.
5d
Sharing all container content
I've understood that SwiftData is not abled to share the whole content of a cloudkit database. So I'm trying to rewrite everything. Does someone knows id Sharing is coming on SwiftData at WWDC 26? Anyway, can someone can point me an example a a configured coredata stack that share all its content with other icloud users (with sharing pane and accept invitation code). At this step, on the owner side, I see some data in the default zone of my private container but nothing is visible on the shared zone. Maybe I don't understand where and when I should check shared data in cloudkit console. Need Help also here. See below by configuration stack: // Core Data container public lazy var container: NSPersistentContainer = { switch delegate.usage() { case .preview : return previewContainer() case .local : return localContainer() case .cloudKit : return cloudKitContainer() } }() private func cloudKitContainer() -> NSPersistentContainer { let modelURL = delegate.modelURL() let modelName = modelURL.deletingPathExtensio
7
0
257
3w
Reply to Sharing all container content
I've already played with the samples and was able to share one by one or a set of records. BUT, let me rephrase, I have a set of entities that I want to share ONCE between invited users with ONE sharing at the top. Could you confirm that is it possible? If Yes, there is probably one missing step or misunderstood in the following code. In my understanding, based on the samples, to do this, I'm doing : 1/ on owner and participant : configure a NSPersistentCloudKitContainer with inside a databaseScope = .private store AND a databaseScope = .shared store 2/ on owner before presenting the UICloudSharingController: 2.1/ create a shared zone-wide share ID let shareRecordID = CKRecord.ID(recordName: CKRecordNameZoneWideShare, zoneID: zoneID) 2.2/ create or get an existing CKShare with: func getOrCreateShare() async throws -> CKShare { let zoneID = CKRecordZone.ID(zoneName: sharedZoneName) // Zone-wide share ID let shareRecordID = CKRecord.ID( recordName: CKRecordNameZoneWideShare, zoneID: zoneID ) // Try
4w
CloudKit Sync Stalls During Initial Large Data Hydration on New Device (SwiftData Local-First Architecture)
Hi everyone, I’m facing an issue with CloudKit sync getting stuck during initial device migration in my SwiftData-based app. The app follows a local-first architecture using SwiftData + CloudKit sync, and works correctly for: ✔ Incremental sync ✔ Bi-directional updates ✔ Small datasets However, when onboarding a new device with large historical data, sync becomes extremely slow or appears stuck. Even after two hours data is not fully synced. ~6900 Transactions 🚨 Problem When installing the app on a new iPhone and enabling iCloud sync: • Initial hydration starts • A small amount of data syncs • Then sync stalls indefinitely Observed behaviour: • iPhone → Mac sync works (new changes sync back) • Mac → iPhone large historical migration gets stuck • Reinstalling app / clearing container does not resolve issue • Sync never completes full migration This gives the impression that: CloudKit is trickling data but not progressing after a certain threshold. The architecture is: • SwiftData local store • Manual CloudKit
1
0
154
4w
Reply to CloudKit Sync Stalls During Initial Large Data Hydration on New Device (SwiftData Local-First Architecture)
For a large dataset, the initial synchronization with CloudKit, which can happen in several cases, including on-boarding a new device, can indeed be slow, or even failed. A similar issue was discussed in this thread as well. Depending on your concrete use case, you might address the issue in the following way: Have your app functional before the dataset is fully synchronized. Synchronize the data in batches in the background, until the whole data set is done. As an example, an email app that is just installed on a new device allows users to compose a new email, while synchronizing existing emails in the background. When using the CloudKit framework, you control what kind and amount of data to be synchronized with CloudKit, and hence can implement the strategy, though the implementation can be quite involved. Now that you are using SwiftData + CloudKit integration, NSPersistentCloudKitContainer takes care the synchronization process. I don't really see anything to work around or mitigate the issue in
4w
CloudKit, CoreData and Swift 6 for sharing between users
I have started from here: Apple's guide on the sharing core data objects between iCloud users and I have created a sample project that has Collections and Items. Everything works great while I stay on Swift 5, like with the initial project. I would like to migrate to Swift 6 (Default Actor Isolaton @MainActor, Approachable Concurrency: Yes) on the project and I am stuck at extension CDCollection: Transferable { ... }. When compiling with Swift 5, there is a warning: Conformance of 'NSManagedObject' to 'Sendable' is unavailable in iOS; this is an error in the Swift 6 language mode. After resolving almost all compile-time warnings I'm left with: Conformance of 'CDCollection' to protocol 'Transferable' crosses into main actor-isolated code and can cause data races. Which I don't think will work, because of the warning shown above. It can be worked around like: nonisolated extension CDCollection: Transferable, @unchecked Sendable Then there are errors: let persistentContainer = PersistenceController.shared.persis
1
0
158
Feb ’26
Reply to SwiftData + CloudKit: BGSystemTaskScheduler Code=8
Just to share a bit more color, the error happens when Core Data + CloudKit schedules a new export task when another one is still in progress. In this situation, the scheduling will fail, and the system will drop the new task. In Core Data + CloudKit, however, I don't think this is an issue, because NSPersistentCloudKitContainer will schedule another export task next time when it detects something yet to export, which can happen some time after it detects that a previous export task failed, or that a new change on the Core Data store was made, and so the data should eventually be exported. You should be able to observe the behavior by capturing and analyzing a sysdiagnose. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Feb ’26
Reply to macOS to macOS SwiftData iCloud Sync Problems
When using SwiftData + CloudKit integration, which uses NSPersistentCloudKitContainer under the hood, the synchronization typically doesn't happen immediately. To better understand the synchronization, consider going through the following technotes: TN3164: Debugging the synchronization of NSPersistentCloudKitContainer TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3162: Understanding CloudKit throttles In your case, the first three bullets are pretty much as-designed. The last one, no edits sync between either Mac, if lasting for ever, which means the synchronization is broken, will be an issue. In that case, you can figure out what happens by capturing and analyzing a sysdiagnose, as described in TN3163. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Feb ’26
Reply to Unable to sync SwiftData model fully using CloudKit
The following console log says that your app detected an account switching at the beginning of the launch process, which may erase the existing data created before the switching. It also says that you were using a simulator. CoreData: warning: CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkUserIdentity:]_block_invoke_3(1487): : CKIdentity record has changed from _b09f3f2b1357d21fdd823f58762f6077 to _4e8dc229775b034192825a3081a709a4 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1242): : Failed to set up CloudKit integration for store: (URL: file:///Users/yuanping_ke/Library/Developer/CoreSimulator/Devices/BA9191E9-6DB4-4A30-9196-0A6C06A11F2E/data/Containers/Data/Application/5977FE0D-50D4-4AE0-8134-5D8B0B662298/Library/Application%20Support/default.store) Later your app did successfully set up CloudKit integration, as shown below, and then did several successful exports and imports, but it seems that there is no change merged into the store. CoreData: warning:
Jan ’26
Unable to sync SwiftData model fully using CloudKit
Hey everyone I just ran into an issue where I couldn't sync the model below fully by using CloudKit, enum LinkMapV3_1: VersionedSchema { static let versionIdentifier: Schema.Version = .init(3, 1, 0) static var models: [any PersistentModel.Type] { [AnnotationData.self, GroupData.self, Item.self, Deployment.self, History.self] } // MARK: - Data @Model class AnnotationData { var name: String = var longitude: Double = 0.0 var latitude: Double = 0.0 var order: Int = -1 var level: Int = 1 var detail: String = @Relationship(deleteRule: .nullify, inverse: GroupData.annotation) var groups: [GroupData]? @Relationship(deleteRule: .nullify, inverse: AnnotationData.to) var from: AnnotationData? var to: AnnotationData? var history: History? } // MARK: - History @Model class History { var id: UUID = UUID() var timestamp: Date = Date() @Relationship(deleteRule: .nullify, inverse: AnnotationData.history) var annotations: [AnnotationData]? @Relationship(deleteRule: .nullify, inverse: GroupData.history) var groups: [GroupData
1
0
300
Jan ’26
Reply to Persisting User Settings with SwiftData
I'd like to comment the second question a bit, as it hasn't been addressed yet: Sometimes when running on a new device it will create a second UserSettings while it is waiting for the original one to sync from CloudKit. When you use SwiftData + CloudKit, under the hood, the framework uses NSPersistentCloudKitContainer to synchronize data. In that environment, duplicate data is sometimes inevitable, which is discussed in great details in the following section: Remove duplicate data The solution is to de-duplicate the data. How to do so is discussed and demonstrated in the sample code. Back to what to what you intent to achieve, my suggestion will be: If you plan to use SwiftData + CloudKit extensively in your app, you might need to handle duplicate data anyway. In this case, persisting user settings to your SwiftData store (and Synchronizing them via NSPersistentCloudKitContainer) makes a lot of sense. If the target is as simple as saving some Cloud-based user settings, I'd probably consider
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’26
Reply to SwiftData @Model: Optional to-many relationship is never nil at runtime
SwiftData default store is based on Core Data. As a historical implementation detail, at runtime, a Core Data to-many relationship, once persisted, is always a [], and never a nil. To adapt this behavior in an effective way, SwiftData always initializes a nil to-many relationship with an empty collection at runtime. So to your first question, the behavior that optional to-many relationships in SwiftData are never nil at runtime is as-designed. The requirement that relationships must be optional is a way to express that NSPersistentCloudKitContainer does not handle relationships atomically, and is enforced by a schema validator at compile time. The validation doesn't have any impact at runtime, and so SwiftData to-many relationships being [] at runtime doesn't break the CloudKit synchronization. To use SwiftData + CloudKit, you make sure your model schema is compatible with the rules so the schema validator doesn't complain, and that will be it. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’26
Extreme increase in app storage size after enabling CloudKit
I have a SwiftData flashcard app which I am syncing with CloudKit using NSPersistentCloudKitContainer. While syncing itself is working perfectly, I have noticed a dramatic increase in the app size after enabling sync. Specifically, without CloudKit, 15k flashcards results in the default.store file being about 4.5 MB. With CloudKit, default.store is about 67 MB. I have inspected the store and found that most of this increase is due to the ANSCKRECORDMETADATA table. My question is, does implementing CloudKit normally cause this magnitude of increase in storage? If it doesn’t, is there something in my model, schema, implementation, etc. that could be causing it? Below are two other posts describing a similar issue, but neither with a solution. I replied to the first one about a month ago. I then submitted this to Developer Technical Support, but was asked to post my question in the forums, so here it is. Strange behavior with 100k+ records in NSPersistentCloudKitContainer Huge increase in sqlit
2
0
206
Jan ’26
Core Data Migration Strategy: store relocation, schema changes and CloudKit adoption in a single release?
I am planning a Core Data migration for a macOS app targeting macOS 12 and later and I would appreciate guidance on structuring the rollout to minimise risk. Context The app currently uses a SQLite store located at: ~/Library/Containers/com.company.AppName/Data/Library/Application Support/AppName I want to: Relocate the persistent store to an app group container: ~/Library/Group Containers/group.com.company.AppName Perform schema migration, including: Renaming attributes Deleting attributes Using a custom NSEntityMigrationPolicy subclass Adopt iCloud sync using NSPersistentCloudKitContainer Potentially leverage staged migration (macOS 14+) Additionally, I intend to port the app to iOS, so the end state needs to support an app group container and CloudKit with the latest schema from the outset. Questions Store relocation vs schema migration Is it advisable to perform store relocation and schema migration in a single step, or should these be separate releases? If combined, are there pitfalls when movin
Replies
3
Boosts
0
Views
91
Activity
2d
Reply to Core Data Migration Strategy: store relocation, schema changes and CloudKit adoption in a single release?
Given that you'd move the Core Data store to a group container, I'd assume that the store will be shared across different processes, such as your main app and its extension (a widget, for example). In that case, I'd like to start with pointing you the following threads: Core Data Light Migration Crash When Widget is Installed (Error 134100). CoreData error=134100 Failed to open the store. These threads made it clear that: After a user installed your new version app, depending on what extension you have, the app and extension can open and migrate the store simultaneously, and so you will need to implement a mechanism to make sure that the store is only migrated once. Consider having your main app in charge of the the synchronization, as discussed in Avoid synchronizing a store with multiple persistent containers. Now to your questions: Store relocation vs schema migration Is it advisable to perform store relocation and schema migration in a single step, or should these be separate releases? If combined, are th
Replies
Boosts
Views
Activity
5d
Reply to CoreData + CloudKit -- Many-to-Many Relationship not Syncing
This sounds like a general synchronization issue, and so you can probably start with the technotes mentioned in this post to hopefully figure out the cause of the issue. NSPersistentCloudKitContainer supports many-to-many relationships. Before seeing an evidence that proves it doesn't work (by going through the debugging process the technotes describe), I probably won't change the Core Data model. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
5d
Sharing all container content
I've understood that SwiftData is not abled to share the whole content of a cloudkit database. So I'm trying to rewrite everything. Does someone knows id Sharing is coming on SwiftData at WWDC 26? Anyway, can someone can point me an example a a configured coredata stack that share all its content with other icloud users (with sharing pane and accept invitation code). At this step, on the owner side, I see some data in the default zone of my private container but nothing is visible on the shared zone. Maybe I don't understand where and when I should check shared data in cloudkit console. Need Help also here. See below by configuration stack: // Core Data container public lazy var container: NSPersistentContainer = { switch delegate.usage() { case .preview : return previewContainer() case .local : return localContainer() case .cloudKit : return cloudKitContainer() } }() private func cloudKitContainer() -> NSPersistentContainer { let modelURL = delegate.modelURL() let modelName = modelURL.deletingPathExtensio
Replies
7
Boosts
0
Views
257
Activity
3w
Reply to Sharing all container content
I've already played with the samples and was able to share one by one or a set of records. BUT, let me rephrase, I have a set of entities that I want to share ONCE between invited users with ONE sharing at the top. Could you confirm that is it possible? If Yes, there is probably one missing step or misunderstood in the following code. In my understanding, based on the samples, to do this, I'm doing : 1/ on owner and participant : configure a NSPersistentCloudKitContainer with inside a databaseScope = .private store AND a databaseScope = .shared store 2/ on owner before presenting the UICloudSharingController: 2.1/ create a shared zone-wide share ID let shareRecordID = CKRecord.ID(recordName: CKRecordNameZoneWideShare, zoneID: zoneID) 2.2/ create or get an existing CKShare with: func getOrCreateShare() async throws -> CKShare { let zoneID = CKRecordZone.ID(zoneName: sharedZoneName) // Zone-wide share ID let shareRecordID = CKRecord.ID( recordName: CKRecordNameZoneWideShare, zoneID: zoneID ) // Try
Replies
Boosts
Views
Activity
4w
CloudKit Sync Stalls During Initial Large Data Hydration on New Device (SwiftData Local-First Architecture)
Hi everyone, I’m facing an issue with CloudKit sync getting stuck during initial device migration in my SwiftData-based app. The app follows a local-first architecture using SwiftData + CloudKit sync, and works correctly for: ✔ Incremental sync ✔ Bi-directional updates ✔ Small datasets However, when onboarding a new device with large historical data, sync becomes extremely slow or appears stuck. Even after two hours data is not fully synced. ~6900 Transactions 🚨 Problem When installing the app on a new iPhone and enabling iCloud sync: • Initial hydration starts • A small amount of data syncs • Then sync stalls indefinitely Observed behaviour: • iPhone → Mac sync works (new changes sync back) • Mac → iPhone large historical migration gets stuck • Reinstalling app / clearing container does not resolve issue • Sync never completes full migration This gives the impression that: CloudKit is trickling data but not progressing after a certain threshold. The architecture is: • SwiftData local store • Manual CloudKit
Replies
1
Boosts
0
Views
154
Activity
4w
Reply to CloudKit Sync Stalls During Initial Large Data Hydration on New Device (SwiftData Local-First Architecture)
For a large dataset, the initial synchronization with CloudKit, which can happen in several cases, including on-boarding a new device, can indeed be slow, or even failed. A similar issue was discussed in this thread as well. Depending on your concrete use case, you might address the issue in the following way: Have your app functional before the dataset is fully synchronized. Synchronize the data in batches in the background, until the whole data set is done. As an example, an email app that is just installed on a new device allows users to compose a new email, while synchronizing existing emails in the background. When using the CloudKit framework, you control what kind and amount of data to be synchronized with CloudKit, and hence can implement the strategy, though the implementation can be quite involved. Now that you are using SwiftData + CloudKit integration, NSPersistentCloudKitContainer takes care the synchronization process. I don't really see anything to work around or mitigate the issue in
Replies
Boosts
Views
Activity
4w
CloudKit, CoreData and Swift 6 for sharing between users
I have started from here: Apple's guide on the sharing core data objects between iCloud users and I have created a sample project that has Collections and Items. Everything works great while I stay on Swift 5, like with the initial project. I would like to migrate to Swift 6 (Default Actor Isolaton @MainActor, Approachable Concurrency: Yes) on the project and I am stuck at extension CDCollection: Transferable { ... }. When compiling with Swift 5, there is a warning: Conformance of 'NSManagedObject' to 'Sendable' is unavailable in iOS; this is an error in the Swift 6 language mode. After resolving almost all compile-time warnings I'm left with: Conformance of 'CDCollection' to protocol 'Transferable' crosses into main actor-isolated code and can cause data races. Which I don't think will work, because of the warning shown above. It can be worked around like: nonisolated extension CDCollection: Transferable, @unchecked Sendable Then there are errors: let persistentContainer = PersistenceController.shared.persis
Replies
1
Boosts
0
Views
158
Activity
Feb ’26
Reply to SwiftData + CloudKit: BGSystemTaskScheduler Code=8
Just to share a bit more color, the error happens when Core Data + CloudKit schedules a new export task when another one is still in progress. In this situation, the scheduling will fail, and the system will drop the new task. In Core Data + CloudKit, however, I don't think this is an issue, because NSPersistentCloudKitContainer will schedule another export task next time when it detects something yet to export, which can happen some time after it detects that a previous export task failed, or that a new change on the Core Data store was made, and so the data should eventually be exported. You should be able to observe the behavior by capturing and analyzing a sysdiagnose. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Feb ’26
Reply to macOS to macOS SwiftData iCloud Sync Problems
When using SwiftData + CloudKit integration, which uses NSPersistentCloudKitContainer under the hood, the synchronization typically doesn't happen immediately. To better understand the synchronization, consider going through the following technotes: TN3164: Debugging the synchronization of NSPersistentCloudKitContainer TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3162: Understanding CloudKit throttles In your case, the first three bullets are pretty much as-designed. The last one, no edits sync between either Mac, if lasting for ever, which means the synchronization is broken, will be an issue. In that case, you can figure out what happens by capturing and analyzing a sysdiagnose, as described in TN3163. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Feb ’26
Reply to Unable to sync SwiftData model fully using CloudKit
The following console log says that your app detected an account switching at the beginning of the launch process, which may erase the existing data created before the switching. It also says that you were using a simulator. CoreData: warning: CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkUserIdentity:]_block_invoke_3(1487): : CKIdentity record has changed from _b09f3f2b1357d21fdd823f58762f6077 to _4e8dc229775b034192825a3081a709a4 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1242): : Failed to set up CloudKit integration for store: (URL: file:///Users/yuanping_ke/Library/Developer/CoreSimulator/Devices/BA9191E9-6DB4-4A30-9196-0A6C06A11F2E/data/Containers/Data/Application/5977FE0D-50D4-4AE0-8134-5D8B0B662298/Library/Application%20Support/default.store) Later your app did successfully set up CloudKit integration, as shown below, and then did several successful exports and imports, but it seems that there is no change merged into the store. CoreData: warning:
Replies
Boosts
Views
Activity
Jan ’26
Unable to sync SwiftData model fully using CloudKit
Hey everyone I just ran into an issue where I couldn't sync the model below fully by using CloudKit, enum LinkMapV3_1: VersionedSchema { static let versionIdentifier: Schema.Version = .init(3, 1, 0) static var models: [any PersistentModel.Type] { [AnnotationData.self, GroupData.self, Item.self, Deployment.self, History.self] } // MARK: - Data @Model class AnnotationData { var name: String = var longitude: Double = 0.0 var latitude: Double = 0.0 var order: Int = -1 var level: Int = 1 var detail: String = @Relationship(deleteRule: .nullify, inverse: GroupData.annotation) var groups: [GroupData]? @Relationship(deleteRule: .nullify, inverse: AnnotationData.to) var from: AnnotationData? var to: AnnotationData? var history: History? } // MARK: - History @Model class History { var id: UUID = UUID() var timestamp: Date = Date() @Relationship(deleteRule: .nullify, inverse: AnnotationData.history) var annotations: [AnnotationData]? @Relationship(deleteRule: .nullify, inverse: GroupData.history) var groups: [GroupData
Replies
1
Boosts
0
Views
300
Activity
Jan ’26
Reply to Persisting User Settings with SwiftData
I'd like to comment the second question a bit, as it hasn't been addressed yet: Sometimes when running on a new device it will create a second UserSettings while it is waiting for the original one to sync from CloudKit. When you use SwiftData + CloudKit, under the hood, the framework uses NSPersistentCloudKitContainer to synchronize data. In that environment, duplicate data is sometimes inevitable, which is discussed in great details in the following section: Remove duplicate data The solution is to de-duplicate the data. How to do so is discussed and demonstrated in the sample code. Back to what to what you intent to achieve, my suggestion will be: If you plan to use SwiftData + CloudKit extensively in your app, you might need to handle duplicate data anyway. In this case, persisting user settings to your SwiftData store (and Synchronizing them via NSPersistentCloudKitContainer) makes a lot of sense. If the target is as simple as saving some Cloud-based user settings, I'd probably consider
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’26
Reply to SwiftData @Model: Optional to-many relationship is never nil at runtime
SwiftData default store is based on Core Data. As a historical implementation detail, at runtime, a Core Data to-many relationship, once persisted, is always a [], and never a nil. To adapt this behavior in an effective way, SwiftData always initializes a nil to-many relationship with an empty collection at runtime. So to your first question, the behavior that optional to-many relationships in SwiftData are never nil at runtime is as-designed. The requirement that relationships must be optional is a way to express that NSPersistentCloudKitContainer does not handle relationships atomically, and is enforced by a schema validator at compile time. The validation doesn't have any impact at runtime, and so SwiftData to-many relationships being [] at runtime doesn't break the CloudKit synchronization. To use SwiftData + CloudKit, you make sure your model schema is compatible with the rules so the schema validator doesn't complain, and that will be it. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jan ’26
Extreme increase in app storage size after enabling CloudKit
I have a SwiftData flashcard app which I am syncing with CloudKit using NSPersistentCloudKitContainer. While syncing itself is working perfectly, I have noticed a dramatic increase in the app size after enabling sync. Specifically, without CloudKit, 15k flashcards results in the default.store file being about 4.5 MB. With CloudKit, default.store is about 67 MB. I have inspected the store and found that most of this increase is due to the ANSCKRECORDMETADATA table. My question is, does implementing CloudKit normally cause this magnitude of increase in storage? If it doesn’t, is there something in my model, schema, implementation, etc. that could be causing it? Below are two other posts describing a similar issue, but neither with a solution. I replied to the first one about a month ago. I then submitted this to Developer Technical Support, but was asked to post my question in the forums, so here it is. Strange behavior with 100k+ records in NSPersistentCloudKitContainer Huge increase in sqlit
Replies
2
Boosts
0
Views
206
Activity
Jan ’26