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


init(share: CKShare, container: CKContainer)



An instance of CKShare that was previously saved.


An instance of CKContainer that contains the record that is shared.


Use the init(share:container:) initializer method to create the UICloudSharingController instance when the user who owns the CKShare record wants to manage the participants and restrictions associated with the share. (For more information, see Adding and Removing Participants from an Existing Share.) You also use this initializer method when users are participants who want to remove themselves from a share. (For more information, see Viewing Participants and Leaving a Share.)

init(share:container:) requires a reference to the CKShare instance associated with the CKRecord instance that represents the shared data. To retrieve the CKShare instance, get the share property value (a CKRecord.Reference instance) from the CKRecord instance. Then pass the recordID from the CKRecord.Reference instance to the fetch(withRecordID:completionHandler:) method on a CKDatabase instance. (Sample code is available in Listing 1.)

Listing 1

Fetch a CKShare record using a CKRecord record.

let record = self.record // A CKRecord
let container = CKContainer.default()
if let shareReference = record.share {
  container.privateCloudDatabase.fetch(withRecordID: shareReference.recordID) { (record, error) in
    guard let shareRecord = record as? CKShare else {
      if let error = error {
    if let url = shareRecord.url {

See Also

Creating the Cloud Sharing Controller

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

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