CloudKit NSPersistentCloudKitContainer Bug

Hi,

does someone knows about the bug, that the NSPersistentCloudKitContainer doesn't return CKShares at the first time? Is this an intended behavior?

My current fix:

let container: NSPersistentCloudKitContainer = ....

// Fix begin
let managedObject = .... // Object which is in a share
let record = container.record(for: managedObject.objectID)
// Fix end


let shares = (try? container.fetchShares(in: nil)) ?? []

If I execute exactly the same code without the fix that I fetch the record first, then it returns 0 shares. With the fix it is currently 9 shares (the actual count of the shares).

Another fix:

let container: NSPersistentCloudKitContainer = ....

// Fix begin
let _ = try? container.fetchShares(in: nil)
Thread.sleep(forTimeInterval: 0.1)
// Fix end


let shares = (try? container.fetchShares(in: nil)) ?? []

For that fix it also returns at the second time the expected count of shares. But without the delay it returns also at the second time zero shares.

Anyone had the same problem and if so, how do you solve it correctly?

Thanks!

CloudKit NSPersistentCloudKitContainer Bug
 
 
Q