{"id":15036952,"url":"https://github.com/apple/sample-cloudkit-sharing","last_synced_at":"2025-04-07T07:07:28.611Z","repository":{"id":43125349,"uuid":"357361948","full_name":"apple/sample-cloudkit-sharing","owner":"apple","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-13T21:53:48.000Z","size":43,"stargazers_count":308,"open_issues_count":5,"forks_count":41,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-31T05:07:02.248Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apple.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-12T23:00:08.000Z","updated_at":"2025-03-22T06:17:14.000Z","dependencies_parsed_at":"2022-07-15T00:46:05.551Z","dependency_job_id":null,"html_url":"https://github.com/apple/sample-cloudkit-sharing","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fsample-cloudkit-sharing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fsample-cloudkit-sharing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fsample-cloudkit-sharing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fsample-cloudkit-sharing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apple","download_url":"https://codeload.github.com/apple/sample-cloudkit-sharing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:32:51.213Z","updated_at":"2025-04-07T07:07:28.573Z","avatar_url":"https://github.com/apple.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CloudKit Samples: Sharing\n\n### Goals\n\nThis project demonstrates sharing CloudKit records across user accounts. It shows how to initiate a share from one user account, and accept the share and subsequently view shared data on another account.\n\n### Prerequisites\n\n* A Mac with [Xcode 13](https://developer.apple.com/xcode/) (or later) installed is required to build and test this project.\n* An active [Apple Developer Program membership](https://developer.apple.com/support/compare-memberships/) is needed to create a CloudKit container.\n\n### Setup Instructions\n\n* Ensure the simulator or device you run the project on is signed in to an Apple ID account with iCloud enabled. This can be done in the Settings app.\n* If you wish to run the app on a device, ensure the correct developer team is selected in the “Signing \u0026 Capabilities” tab of the Sharing app target, and a valid iCloud container is selected under the “iCloud” section.\n\n#### Using Your Own iCloud Container\n\n* Create a new iCloud container through Xcode’s “Signing \u0026 Capabilities” tab of the Sharing app target.\n* Update the `containerIdentifier` property in [Config.swift](Sharing/App/Config.swift) with your new iCloud container ID.\n\n### How it Works\n\n#### User One: Initiating the Share\n\n* On either a device or simulator with a signed-in iCloud account, User One creates a new Contact record through the UI with a name and phone number. The Contact is saved to the user’s private iCloud database with the `addContact(name:phoneNumber:completionHandler)` function in ViewModel.swift.\n\n* After the Contacts list is refreshed, the newly added Contact will appear under the “Private” section of the UI.\n\n* Tapping the share button on the Contact list entry creates a `CKShare` object and writes it to the database with the `createShare(contact:completionHandler)` function in ViewModel.swift. After the share is created, the `CloudSharingView` is displayed which wraps [UICloudSharingController](https://developer.apple.com/documentation/uikit/uicloudsharingcontroller) in a SwiftUI compatible view. This view allows the user to configure share options and send or copy the share link to share with User Two.\n\n#### User Two: Accepting the Share Invitation\n\n* On a separate device with a different signed-in iCloud account, User Two accepts the share by following the link provided by User One.\n\n* The link initiates a prompt on the user’s device to accept the share, which launches the Sharing app and accepts the share through a database operation defined in SceneDelegate’s `userDidAcceptCloudKitShareWith` delegate callback.\n\n* After the share is accepted and the UI is refreshed, the shared Contact will display in User Two’s Contacts list in the “Shared” section. `fetchSharedContacts(completionHandler:)` in ViewModel.swift shows how Contacts in shared database zones are fetched.\n\n### Note on Swift Concurrency\n\nThis project uses Swift concurrency APIs. A prior `completionHandler`-based implementation has been tagged [`pre-async`](https://github.com/apple/cloudkit-sample-sharing/tree/pre-async).\n\n### Further Reading\n\n* [Sharing CloudKit Data with Other iCloud Users](https://developer.apple.com/documentation/cloudkit/shared_records/sharing_cloudkit_data_with_other_icloud_users)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapple%2Fsample-cloudkit-sharing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapple%2Fsample-cloudkit-sharing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapple%2Fsample-cloudkit-sharing/lists"}