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


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



The block invoked by UICloudSharingController when it is time for your application to save a newly created CKShare record.


Use the init(preparationHandler:) initializer method to create a new UICloudSharingController instance when the user who owns a CKRecord wants to share the record with other people. To determine if the record is shared, check its share property. If the property value is nil, the record is not shared, and this method is the one to use.

The preparationHandler: provided to the initializer method is responsible for saving the new CKShare record. The handler has two parameters:

  • A reference to the UICloudSharingController instance that called the preparation handler

  • A reference to a completion block

After you save the new CKShare record and its root record (the CKRecord representing the data to share) in the preparation handler, you call the completion block. Calling the completion block tells the UICloudSharingController instance to continue with the invitation workflow.

For more information and sample code, see Inviting Participants to a New Share.

See Also

Creating the Cloud Sharing Controller

init(share: CKShare, container: CKContainer)

Initializes the CloudKit sharing view controller with a CloudKit share record and container to manage participants and restrictions.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software