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.
Post
Replies
Boosts
Views
Activity
I have the same issue, which i posted about here: https://developer.apple.com/forums/thread/691268
Can’t wait to try this out. Hopefully I can remove all my custom CloudKit code.
I have the same question. Right now, I'm importing SwiftUI in my other classes and using @AppStorage the same as I would inside a View. But importing SwiftUI outside of a View seems like not the right thing to do.
That said, I don't want to have use UserDefaults directly in some parts of my code, and @AppStorage in others. And, as you point out, @SceneStorage is another use case.
I'd be interested in what others think.