I've been searching all over the web trying to find the proper way to get all records created by a specific user in CloudKit.
I am able to get the correct id using:
guard let userRecordID = try? await container.userRecordID() else { return }
I can see that the id returned is associated with records in my CloudKit dashboard. So I would expect that the following would get those records:
let predicate = NSPredicate(format: "%K == %@", #keyPath(CKRecord.creatorUserRecordID), userRecordID)
let query = CKQuery(recordType: "CKUser", predicate: predicate)
But instead when I use that query it returns nothing. It is successful but with nothing returned...
Any ideas why this would be happening?
P.S. I have also tried constructing the predicate using the reference, but I get the same result - success with no results.
P.S.2 Also worth mentioning that I am trying to get the results from the public database and I have set my CKContainer to the correct container id.
... The existing records are not showing when I do the query you suggested previously, but if I create a new record from CloudKit console then it shows in the query. Also if I edit a record using CloudKit console with the iCloud user then it shows...
Yeah, this does seem like CloudKit doesn't index the existing data correctly. In this situation, the best I can suggest is that you file a feedback report to request that the CloudKit team helps re-index your CloudKit container, and follow up with the team from there.
When you file the feedback report, make sure it has the following information:
- A detailed description of the issue, including the information you provided in this forum post.
- Your CloudKit container ID.
- Your developer account name.
- Your App Store app name and link impacted by this issue, if any.
When you have the feedback report ID, please share here. I'd be happy to route it directly to the team for them to decide what they can do.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.