Deleting a Share without deleting Objects

Hi,

I wanted to offer the UI for editing and deleting a share. So for using

UICloudSharingController(share: , container: )

I implemented the delegate to call "persistUpdatedShare" in "cloudSharingControllerDidSaveShare"

func cloudSharingControllerDidSaveShare(_ csc: UICloudSharingController) {
		if let share = csc.share,
		   let privatePersistentStore = PersistenceController.shared.privatePersistentStore {
PersistenceController.shared.container.persistUpdatedShare(share, in: privatePersistentStore) { (share, error) in
				Thread.performOnMain {
					if let error = error {
						PersistenceController.shared.storeWarning = error
					}
				}
			}
		}
	}

and to call "purgeObjectsAndRecordsInZone" in "cloudSharingControllerDidStopSharing"

	func cloudSharingControllerDidStopSharing(_ csc: UICloudSharingController) {
		let puzzleToShare = puzzleToShare
		if let share = csc.share,
		   let privatePersistentStore = PersistenceController.shared.privatePersistentStore {
PersistenceController.shared.container.purgeObjectsAndRecordsInZone(with: share.recordID.zoneID,
																				in: privatePersistentStore) { (zoneID, error) in
				Thread.performOnMain {
					if let error = error {
						PersistenceController.shared.storeWarning = error
					} else {
						puzzleToShare.makePrivateDuplicate()
						try? puzzleToShare.puzzle.managedObjectContext?.save()
					}
				}
			}
		}

	}

I got this implementation from a TSI, but it makes no sense to me to delete and duplicate my objects rather than just keeping them and only deleting the share.

Question: How can I cleanly discontinue a share, but keep my data. Duplicating my objects seems such a weird approach. But without this implementation it does not really work. (I get strange behaviors and crashes)

All the best Christoph

  • I'm stuck with the same problem. Did you figure out a solution? And if not, could you share your makePrivateDuplicate() function? Maybe in my use case a duplication of the (ex-)share will work.

Add a Comment