shareManagedObjects:toShare:completion:
Associates the specified managed objects with a new or existing share record.
Declaration
- (void) shareManagedObjects:(NSArray<NSManagedObject *> *) managedObjects toShare:(CKShare *) share completion:(void (^)(NSSet<NSManagedObjectID *> *sharedObjectIDs, CKShare *share, CKContainer *cloudKitContainer, NSError *sharingError)) completion;Parameters
- managedObjects:
The managed objects to share.
- share:
A share record that identifies an existing shared record zone to associate the managed objects with. Use
nilto create a new shared record zone that contains only the specified managed objects and doesn’t have any participants. - completion:
The handler to invoke after Core Data shares the managed objects.
Discussion
The completion closure returns no value and takes the following parameters:
The IDs of the shared objects.
The share record. For more information, see CKShare.
The CloudKit container of the database that stores the shared record zone. For more information, see CKContainer.
An error object that contains information about a problem, or
nilif the managed objects share successfully.
When you invoke this method, Core Data performs a deep traversal among the specified managed objects and adds any related objects to the share.
Sharing fails if any of the following conditions apply:
Any objects in
managedObjects, or those the traversal finds, belong to an existing share record.Any objects in
managedObjectsbelong to a persistent store that doesn’t support sharing, such as those you configure with the CKDatabase.Scope.public database scope.The current device state doesn’t support sharing, such as when there isn’t an active iCloud account.
You can use completion directly with the init(preparationHandler:) method of UICloudSharingController, as the following example shows.