<!--
{
  "availability" : [
    "iOS: 10.0.0 - 17.0.0",
    "iPadOS: 10.0.0 - 17.0.0",
    "macCatalyst: 13.1.0 - 17.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICloudSharingController/init(preparationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UICloudSharingController(im)initWithPreparationHandler:"
  },
  "title" : "init(preparationHandler:)"
}
-->

# init(preparationHandler:)

Initializes the CloudKit sharing controller with a preparation handler intending to save a new share record.

```
init(preparationHandler: @escaping (UICloudSharingController, @escaping (CKShare?, CKContainer?, (any Error)?) -> Void) -> Void)
```

## Parameters

`preparationHandler`

The block invoked by [`UICloudSharingController`](/documentation/UIKit/UICloudSharingController) when it is time for your application to save a newly created <doc://com.apple.documentation/documentation/CloudKit/CKShare> record.

## Discussion

Use the [`init(preparationHandler:)`](/documentation/UIKit/UICloudSharingController/init(preparationHandler:)) initializer method to create a new [`UICloudSharingController`](/documentation/UIKit/UICloudSharingController) instance when the user who owns a <doc://com.apple.documentation/documentation/CloudKit/CKRecord> wants to share the record with other people. To determine if the record is shared, check its <doc://com.apple.documentation/documentation/CloudKit/CKRecord/share> property. If the property value is `nil`, the record is not shared, and this method is the one to use.

> Important:
> You must initialize the controller with the correct initializer method. Do not use ``doc://com.apple.uikit/documentation/UIKit/UICloudSharingController/init(preparationHandler:)`` if the <doc://com.apple.documentation/documentation/CloudKit/CKRecord> is already shared. Likewise, do not use ``doc://com.apple.uikit/documentation/UIKit/UICloudSharingController/init(share:container:)`` if the <doc://com.apple.documentation/documentation/CloudKit/CKRecord> is not shared. Using the wrong initializer leads to errors when saving the record.

The `preparationHandler:` provided to the initializer method is responsible for saving the new <doc://com.apple.documentation/documentation/CloudKit/CKShare> record. The handler has two parameters:

- A reference to the [`UICloudSharingController`](/documentation/UIKit/UICloudSharingController) instance that called the preparation handler
- A reference to a completion block

After you save the new <doc://com.apple.documentation/documentation/CloudKit/CKShare> record and its root record (the <doc://com.apple.documentation/documentation/CloudKit/CKRecord> representing the data to share) in the preparation handler, you call the completion block. Calling the completion block tells the [`UICloudSharingController`](/documentation/UIKit/UICloudSharingController) instance to continue with the invitation workflow.

For more information and sample code, see [`Inviting participants to a new share`](/documentation/UIKit/UICloudSharingController#Inviting-participants-to-a-new-share).

---

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)