<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKShare",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKShare"
  },
  "title" : "CKShare"
}
-->

# CKShare

A specialized record type that manages a collection of shared records.

```
class CKShare
```

## Overview

A share is a specialized record type that facilitates the sharing of one or more records with many participants. You store shareable records in a custom record zone in the user’s private database. As you create records in that zone, they become eligible for record zone sharing. If you want to share a specific hierarchy of related records, rather than the entire record zone, set each record’s [`parent`](/documentation/CloudKit/CKRecord/parent) property to define the relationship with its parent. CloudKit infers the shared hierarchy using only the [`parent`](/documentation/CloudKit/CKRecord/parent) property, and ignores any custom reference fields.

You create a share with either the ID of the record zone to share, or the root record, which defines the point in a record hierarchy where you want to start sharing. CloudKit shares all the records in the record zone, or every record in the hierarchy below the root. If you set the root record’s [`parent`](/documentation/CloudKit/CKRecord/parent) property, CloudKit ignores it. A record can take part in only a single share. This applies to every record in the shared record zone or hierarchy. If a record is participating in another share, any attempt to save the share fails, and CloudKit returns an [`alreadyShared`](/documentation/CloudKit/CKError/alreadyShared) error.

Use [`CKModifyRecordsOperation`](/documentation/CloudKit/CKModifyRecordsOperation) to save the share to the server. The initial set of records the share includes must exist on the server or be part of the same save operation to succeed. CloudKit then updates the share’s [`url`](/documentation/CloudKit/CKShare/url) property. Use <doc://com.apple.documentation/documentation/UIKit/UICloudSharingController> to present options to the user for sharing the URL. Otherwise, distribute the URL to any participants you add to the share. You can allow anyone with the URL to take part in the share by setting [`publicPermission`](/documentation/CloudKit/CKShare/publicPermission) to a value more permissive than [`CKShare.ParticipantPermission.none`](/documentation/CloudKit/CKShare/ParticipantPermission/none).

> Important: You must add the <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/CKSharingSupported> key to your app’s `Info.plist` file with a value of `true`. This allows the system to launch your app when a user taps or clicks the URL.

After CloudKit saves the share, a participant can fetch its corresponding metadata, which includes a reference to the share, information about the user’s participation, and, for shared hierarchies, the root record’s record ID. Create an instance of [`CKFetchShareMetadataOperation`](/documentation/CloudKit/CKFetchShareMetadataOperation) using the share’s URL and add it to the container’s queue to execute it. The operation returns an instance of [`CKShare.Metadata`](/documentation/CloudKit/CKShare/Metadata) for each URL you provide. This is only applicable if you manually process share acceptance. If a user receives the share URL and taps or clicks it, CloudKit automatically processes their participation.

To determine the configuration of a fetched share, inspect the [`recordName`](/documentation/CloudKit/CKRecord/ID/recordName) property of its [`recordID`](/documentation/CloudKit/CKRecord/recordID). If the value is [`CKRecordNameZoneWideShare`](/documentation/CloudKit/CKRecordNameZoneWideShare), the share is managing a shared record zone; otherwise, it’s managing a shared record hierarchy.

```swift
let isZoneWide = (metadata.share.recordID.recordName == CKRecordNameZoneWideShare)
```

CloudKit limits the number of participants in a share to 100, and each participant must have an active iCloud account. You don’t create participants. Instead, use <doc://com.apple.documentation/documentation/UIKit/UICloudSharingController> to manage a share’s participants and their permissions. Alternatively, create an instance of [`CKUserIdentity.LookupInfo`](/documentation/CloudKit/CKUserIdentity/LookupInfo-swift.class) for each user. Provide the user’s email address or phone number, and use [`CKFetchShareParticipantsOperation`](/documentation/CloudKit/CKFetchShareParticipantsOperation) to fetch the corresponding participants. CloudKit queries iCloud for corresponding accounts as part of the operation. If it doesn’t find an account, the server updates the participant’s [`userIdentity`](/documentation/CloudKit/CKShare/Participant/userIdentity) to reflect that by setting the [`hasiCloudAccount`](/documentation/CloudKit/CKUserIdentity/hasiCloudAccount) property to <doc://com.apple.documentation/documentation/Swift/false>. CloudKit associates the participant with their iCloud account when they accept the share if they launch the process by tapping or clicking the share URL.

Participants with write permissions can modify or delete any record that you include in the share. However, only the owner can delete a shared hierarchy’s root record. If a participant attempts to delete the share, CloudKit removes the participant. The share remains active for all other participants. If the owner deletes a share that manages a record hierarchy, CloudKit sets the root record’s [`share`](/documentation/CloudKit/CKRecord/share) property to `nil`. CloudKit deletes the share if the owner of the shared hierarchy deletes its root record.

You can customize the title and image the system displays when initiating a share or accepting an invitation to participate. You can also provide a custom UTI to indicate the content of the shared records. Use the keys that [`CKShare.SystemFieldKey`](/documentation/CloudKit/CKShare/SystemFieldKey) defines, as the following example shows:

```swift
let share = CKShare(rootRecord: album)

// Configure the share so the system displays the album's
// name and cover when the user initiates sharing or accepts
// an invitation to participate.
share[CKShare.SystemFieldKey.title] = album["name"]
if let cover = album["cover"] as? UIImage, let data = cover.pngData() {
    share[CKShare.SystemFieldKey.thumbnailImageData] = data
}
// Include a custom UTI that describes the share's content.
share[CKShare.SystemFieldKey.shareType] = "com.example.app.album"
```

## Topics

### Creating a Share

[`init(coder:)`](/documentation/CloudKit/CKShare/init(coder:))

Creates a share from a serialized instance.

[`init(rootRecord:)`](/documentation/CloudKit/CKShare/init(rootRecord:))

Creates a new share for the specified record.

[`init(rootRecord:shareID:)`](/documentation/CloudKit/CKShare/init(rootRecord:shareID:))

Creates a new share for the specified record and record ID.

[`init(recordZoneID:)`](/documentation/CloudKit/CKShare/init(recordZoneID:))

Creates a new share for the specified record zone.

### Accessing the Share’s Attributes

[`owner`](/documentation/CloudKit/CKShare/owner)

The participant that represents the share’s owner.

[`currentUserParticipant`](/documentation/CloudKit/CKShare/currentUserParticipant)

The participant that represents the current user.

[`participants`](/documentation/CloudKit/CKShare/participants)

An array that contains the share’s participants.

[`url`](/documentation/CloudKit/CKShare/url)

The Uniform Resource Locator (URL) for inviting participants to the share.

### Configuring the Share

[`publicPermission`](/documentation/CloudKit/CKShare/publicPermission)

The permission for anyone with access to the share’s URL.

[`addParticipant(_:)`](/documentation/CloudKit/CKShare/addParticipant(_:))

Adds a participant to the share.

[`removeParticipant(_:)`](/documentation/CloudKit/CKShare/removeParticipant(_:))

Removes a participant from the share.

[`CKShare.Participant`](/documentation/CloudKit/CKShare/Participant)

An object that describes a user’s participation in a share.

### Accessing Metadata

[`CKShare.Metadata`](/documentation/CloudKit/CKShare/Metadata)

An object that describes a shared record’s metadata.

### Subscripting

[`CKShare.SystemFieldKey`](/documentation/CloudKit/CKShare/SystemFieldKey)

Constants that represent the system fields of a share.

[`CKShareTypeKey`](/documentation/CloudKit/CKShareTypeKey-204gl)

The system field key for the share’s type.

[`CKShareTitleKey`](/documentation/CloudKit/CKShareTitleKey-9yavd)

The system field key for the share’s title.

[`CKShareThumbnailImageDataKey`](/documentation/CloudKit/CKShareThumbnailImageDataKey-1rxdx)

The system field key for the share’s thumbnail image data.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)