import SharedWithYou import SwiftUI struct CollaborationButton: NSViewRepresentable { let fileURL: URL func makeNSView(context: Context) -> SWCollaborationView { let itemProvider = NSItemProvider(contentsOf: fileURL)! let view = SWCollaborationView(itemProvider: itemProvider) view.activeParticipantCount = 0 view.cloudSharingDelegate = context.coordinator return view } func updateNSView(_ nsView: SWCollaborationView, context: Context) { // Update participant count as needed } func makeCoordinator() -> Coordinator { Coordinator(fileURL: fileURL) } class Coordinator: NSObject, NSCloudSharingServiceDelegate { let fileURL: URL init(fileURL: URL) { self.fileURL = fileURL } func sharingService( _ sharingService: NSSharingService, didFailToShareItems items: [Any], error: Error ) { print("Failed to share: \(error)") } func sharingService( _ sharingService: NSSharingService, didCompleteForItems items: [Any] ) { print("Sharing completed") } func options(for: NSSharingService, share: NSItemProvider) -> NSSharingService.CloudKitOptions { return [.allowPublic, .allowPrivate, .allowReadWrite] } } }