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

# init(share:container:)

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

```
init(share: CKShare, container: CKContainer)
```

## Parameters

`share`

An instance of <doc://com.apple.documentation/documentation/CloudKit/CKShare> that was previously saved.

`container`

An instance of <doc://com.apple.documentation/documentation/CloudKit/CKContainer> that contains the record that is shared.

## Discussion

Use the [`init(share:container:)`](/documentation/UIKit/UICloudSharingController/init(share:container:)) initializer method to create the [`UICloudSharingController`](/documentation/UIKit/UICloudSharingController) instance when the user who owns the <doc://com.apple.documentation/documentation/CloudKit/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`](/documentation/UIKit/UICloudSharingController#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`](/documentation/UIKit/UICloudSharingController#Viewing-participants-and-leaving-a-share).)

> 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.

[`init(share:container:)`](/documentation/UIKit/UICloudSharingController/init(share:container:)) requires a reference to the <doc://com.apple.documentation/documentation/CloudKit/CKShare> instance associated with the <doc://com.apple.documentation/documentation/CloudKit/CKRecord> instance that represents the shared data. To retrieve the <doc://com.apple.documentation/documentation/CloudKit/CKShare> instance, get the <doc://com.apple.documentation/documentation/CloudKit/CKRecord/share> property value (a <doc://com.apple.documentation/documentation/CloudKit/CKRecord/Reference> instance) from the <doc://com.apple.documentation/documentation/CloudKit/CKRecord> instance. Then pass the <doc://com.apple.documentation/documentation/CloudKit/CKRecord/Reference/recordID> from the <doc://com.apple.documentation/documentation/CloudKit/CKRecord/Reference> instance to the <doc://com.apple.documentation/documentation/CloudKit/CKDatabase/fetch(withRecordID:completionHandler:)> method on a <doc://com.apple.documentation/documentation/CloudKit/CKDatabase> instance, as shown in the following code.

```objc
CKRecord *record = [self record];
CKReference *shareReference = [record share];
if (shareReference == nil) {
  return;
}
CKContainer *container = [CKContainer defaultContainer];
[[container privateCloudDatabase] fetchRecordWithID:[shareReference recordID] completionHandler:^(CKRecord * _Nullable record, NSError * _Nullable error) {
  
  if (record == nil) {
    NSLog(@"%@", [error localizedDescription]);
  } else if ([record isKindOfClass:[CKShare class]]) {
    CKShare *shareRecord = (CKShare *)record;
    NSLog(@"%@", [shareRecord URL]);
  }
  
}];
```

---

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)