UICloudSharingContainer equivalent on macOS (i.e. SwiftUI)?

I'm trying to write a SwiftUI iOS/macOS app that allows users to collaborate, but I keep running into limitations. The latest is that I can't figure out what the UICloudSharingContainer equivalent is on macOS. It doesn't seem like there’s a SwiftUI version of this, so I have to write a lot of platform-specific code to handle it, but it's not clear what the AppKit equivalent is.

Answered by DTS Engineer in 810486022

If UICloudSharingContainer means UICloudSharingController here, its counterpart on macOS is NSSharingServicePicker. If you are making a SwiftUI app, consider using ShareLink to create a new share (CKShare), and using UIActivityViewController / NSSharingServicePicker to manage a share.

The following sample should give you a starting point:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Accepted Answer

If UICloudSharingContainer means UICloudSharingController here, its counterpart on macOS is NSSharingServicePicker. If you are making a SwiftUI app, consider using ShareLink to create a new share (CKShare), and using UIActivityViewController / NSSharingServicePicker to manage a share.

The following sample should give you a starting point:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Oh thank you, @DTS Engineer, that's helpful. Yes, I meant UICloudSharingController. I had completely failed to remember ShareLink, not realizing it works for this case.

Ideally, I'd be able to use SwiftData for the bulk of my local objects, but afaik there’s no direct support for CKShare in SwiftData.

Can you tell me if I have to create the Core Data stack from scratch, or can I insert the necessary bits (e.g. all the descriptions and options for shared zones, etc.) into the stack created by the Swift Data APIs?

Regarding SwiftData + CloudKit share, I mentioned my opinion in the following post, which I think answers your question as well:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you. It sounds like the best approach is to start with a standard/traditional Core Data stack and "migrate" to Swift Data from there.

UICloudSharingContainer equivalent on macOS (i.e. SwiftUI)?
 
 
Q