---
title: "prepareShare(container:allowedSharingOptions:preparationHandler:)"
framework: cloudkit
role: symbol
role_heading: Type Method
path: "cloudkit/cksharetransferrepresentation/exportedshare/prepareshare(container:allowedsharingoptions:preparationhandler:)"
---

# prepareShare(container:allowedSharingOptions:preparationHandler:)

Creates a share when the system calls the specified handler.

## Declaration

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

## Parameters

- `container`: The doc://com.apple.cloudkit/documentation/CloudKit/CKContainer for the share.
- `allowedSharingOptions`: The doc://com.apple.cloudkit/documentation/CloudKit/CKAllowedSharingOptions. The doc://com.apple.cloudkit/documentation/CloudKit/CKAllowedSharingOptions/standard option is the default.
- `preparationHandler`: The handler the system calls in your app to create a new doc://com.apple.cloudkit/documentation/CloudKit/CKShare.

## Return Value

Return Value The CKShareTransferRepresentation.ExportedShare with the new CKShare.

## Discussion

Discussion Use this method when you want to share a collection of CKRecord objects, but don’t currently have a CKShare. When the system calls the preparationHandler, create a new CKShare with the appropriate root CKRecord or CKRecordZone.ID. After saving the share and all records to the server, return the resulting CKShare or throw an error if saving fails. When your app invokes the share sheet with a CKShare registered with this method, the system prompts the user to start sharing.

## See Also

### Preparing an exported share

- [existing(_:container:allowedSharingOptions:)](cloudkit/cksharetransferrepresentation/exportedshare/existing(_:container:allowedsharingoptions:).md)
