<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKShareTransferRepresentation/ExportedShare/prepareShare(container:allowedSharingOptions:preparationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "s:8CloudKit29CKShareTransferRepresentationV13ExportedShareV07prepareG09container21allowedSharingOptions18preparationHandlerAEyx_GSo11CKContainerC_So09CKAllowedkL0CSo0C0CyYaYbKctFZ"
  },
  "title" : "prepareShare(container:allowedSharingOptions:preparationHandler:)"
}
-->

# prepareShare(container:allowedSharingOptions:preparationHandler:)

Creates a share when the system calls the specified handler.

```
static func prepareShare(container: CKContainer, allowedSharingOptions: CKAllowedSharingOptions = CKAllowedSharingOptions.standard, preparationHandler: @escaping @Sendable () async throws -> CKShare) -> CKShareTransferRepresentation<Item>.ExportedShare
```

## Parameters

`container`

The [`CKContainer`](/documentation/CloudKit/CKContainer) for the share.

`allowedSharingOptions`

The [`CKAllowedSharingOptions`](/documentation/CloudKit/CKAllowedSharingOptions). The [`standard`](/documentation/CloudKit/CKAllowedSharingOptions/standard) option is the default.

`preparationHandler`

The handler the system calls in your app to create a new [`CKShare`](/documentation/CloudKit/CKShare).

## Return Value

The [`CKShareTransferRepresentation.ExportedShare`](/documentation/CloudKit/CKShareTransferRepresentation/ExportedShare) with the new [`CKShare`](/documentation/CloudKit/CKShare).

## Discussion

Use this method when you want to share a collection of [`CKRecord`](/documentation/CloudKit/CKRecord) objects, but don’t currently have a [`CKShare`](/documentation/CloudKit/CKShare).

When the system calls the `preparationHandler`, create a new [`CKShare`](/documentation/CloudKit/CKShare) with the appropriate root [`CKRecord`](/documentation/CloudKit/CKRecord) or [`CKRecordZone.ID`](/documentation/CloudKit/CKRecordZone/ID).

After saving the share and all records to the server, return the resulting [`CKShare`](/documentation/CloudKit/CKShare) or throw an error if saving fails.
When your app invokes the share sheet with a [`CKShare`](/documentation/CloudKit/CKShare) registered with this method, the system prompts the user to start sharing.

---

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)