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