Post

Replies

Boosts

Views

Activity

Reply to NSPersistentCloudKitContainer: how to un-share objects?
I worked around this by always checking to see if the share actually exists in CloudKit, rather than relying on the existence of a CKShare from fetchShares(matching:). I get the URL from the CKShare returned from fetchShares(matching:) and call this: private func remoteShare(at url: URL) async throws -> CKShare? { do { let metadata = try await cloudKitContainer.shareMetadata(for: url) return metadata.share } catch let error as CKError { if error.retryable { throw RemoteError.retryable } else if error.userInterventionRequiredError { throw RemoteError.userInterventionRequired } else if error.code == .unknownItem { return nil } else { throw RemoteError.remoteFailure } } catch { throw RemoteError.remoteFailure } } } If I get unknownItem that means there is no share on the remote, so the object is not actually shared. The RemoteError is my custom error handling, and I have some extensions on CKError to categorize the errors. I hope this helps.
Oct ’21