Post

Replies

Boosts

Views

Activity

Reply to Sharing all container content
I'm not sure we understand each other correctly. The goal is for a person to start setting up storage spaces in their home to manage product storage. This person then sends out several invitations (for example, to family members) so that everyone can manage all storage spaces and products with the same rights: adding, modifying, and deleting records. If I understand correctly, a public database is visible to all users of the application without the need for an invitation. So this is not the solution for my use case? I want a space shared between a few users brought together by invitations sent out by an initiator. Once these people are together, they work together on all the content in the database, including additions, without the need for new specific invitations.
Topic: App & System Services SubTopic: iCloud Tags:
Mar ’26
Reply to Sharing all container content
I want to share all the content of a CloudKit database at once between different iCloud accounts. For example, to manage products storage between users. Once the database has been shared or an invitation has been accepted, any additions/modifications/deletions to storage or products must be shared between all users without additional sharing. To be short after the first sharing, everything must be shared without additional new sharing. I think I can't do this in SwiftData (would be the best solution for me as all the current app is based on SwiftDaa) and that I need to use move to CoreData. Is that correct? Or does a mixed solution may be possible (ie .storage with SWiftData and sharing with CoreData)? It seems that “Zone Wide Sharing” could be the solution? But I can't find a sufficiently comprehensive example and I wasn't able to make something working. Ultimately, I realize that this is not a very common use case. With the "ZoneWide Sharing" does it means that we must do a affectedStores or assign(_:to:) to the shared store each time we insert a new managed objects? If you can I'm ok to share my projet with in private and then I can make a summary of the solution to share here. In all cases, I working on a smallest as possible example app.
Topic: App & System Services SubTopic: iCloud Tags:
Mar ’26
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 to fetch existing share do { let existingShare = try await privateDatabase.record(for: shareRecordID) as? CKShare if let share = existingShare { print("Existing share retrieved") return share } } catch let error as CKError where error.code == .unknownItem { print("No existing share, creating new one for the entire zone") let share = CKShare(recordZoneID: zoneID) share[CKShare.SystemFieldKey.title] = "My Sharing Title" as CKRecordValue share[CKShare.SystemFieldKey.shareType] = "net.megy.stokk.inventory" as CKRecordValue share.publicPermission = .none // Private only guard let savedShare = try await privateDatabase.save(share) as? CKShare else { throw CKError(.unknownItem) } print("Return new share created for entire zone") return savedShare } // should not be reached throw CKError(.unknownItem) } 3/ on the participant side, that I've plugged my SceneDelegate windowScene(_ windowScene:userDidAcceptCloudKitShareWith:) to accep the invitation with: public func acceptShare(metadata: CKShare.Metadata) async throws { try await CKContainer(identifier: cloudKitIdentifier).accept(metadata) print("Invitation accepted, syncing...") }
Topic: App & System Services SubTopic: iCloud Tags:
Mar ’26
Reply to Sharing all container content
I'm not sure we understand each other correctly. The goal is for a person to start setting up storage spaces in their home to manage product storage. This person then sends out several invitations (for example, to family members) so that everyone can manage all storage spaces and products with the same rights: adding, modifying, and deleting records. If I understand correctly, a public database is visible to all users of the application without the need for an invitation. So this is not the solution for my use case? I want a space shared between a few users brought together by invitations sent out by an initiator. Once these people are together, they work together on all the content in the database, including additions, without the need for new specific invitations.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Mar ’26
Reply to Sharing all container content
I want to share all the content of a CloudKit database at once between different iCloud accounts. For example, to manage products storage between users. Once the database has been shared or an invitation has been accepted, any additions/modifications/deletions to storage or products must be shared between all users without additional sharing. To be short after the first sharing, everything must be shared without additional new sharing. I think I can't do this in SwiftData (would be the best solution for me as all the current app is based on SwiftDaa) and that I need to use move to CoreData. Is that correct? Or does a mixed solution may be possible (ie .storage with SWiftData and sharing with CoreData)? It seems that “Zone Wide Sharing” could be the solution? But I can't find a sufficiently comprehensive example and I wasn't able to make something working. Ultimately, I realize that this is not a very common use case. With the "ZoneWide Sharing" does it means that we must do a affectedStores or assign(_:to:) to the shared store each time we insert a new managed objects? If you can I'm ok to share my projet with in private and then I can make a summary of the solution to share here. In all cases, I working on a smallest as possible example app.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Mar ’26
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 to fetch existing share do { let existingShare = try await privateDatabase.record(for: shareRecordID) as? CKShare if let share = existingShare { print("Existing share retrieved") return share } } catch let error as CKError where error.code == .unknownItem { print("No existing share, creating new one for the entire zone") let share = CKShare(recordZoneID: zoneID) share[CKShare.SystemFieldKey.title] = "My Sharing Title" as CKRecordValue share[CKShare.SystemFieldKey.shareType] = "net.megy.stokk.inventory" as CKRecordValue share.publicPermission = .none // Private only guard let savedShare = try await privateDatabase.save(share) as? CKShare else { throw CKError(.unknownItem) } print("Return new share created for entire zone") return savedShare } // should not be reached throw CKError(.unknownItem) } 3/ on the participant side, that I've plugged my SceneDelegate windowScene(_ windowScene:userDidAcceptCloudKitShareWith:) to accep the invitation with: public func acceptShare(metadata: CKShare.Metadata) async throws { try await CKContainer(identifier: cloudKitIdentifier).accept(metadata) print("Invitation accepted, syncing...") }
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Mar ’26
Reply to SwiftData with shared and private containers
Same problem for me !!!! use SwiftData, build great apps and POC… Then when you'll need sharing rewrite everything with coredata (that you may not mastered). As an independent developer it is really a pain. At least If I was sure that the sharing feature is schedule!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’26