#StackBounty: #swift #cloudkit How to query CloudKit by lastModifiedUserRecordID?

Bounty: 50

Based on Apple documentation, lastModifiedUserRecordID, is a system field that’s auto generated on iCloud.

I want to fetch records from the public iCloud database that where last modified by me.

I set “modifiedBy” as Queryable on the CloudKit Dashboard and added this predicate:

let userId = CKRecord.Reference(recordID: userCKRecordID, action: .none)
lastModifiedPred = NSPredicate(format: "lastModifiedUserRecordID = %@", userId)

And it returns no results. If I remove this predicate, it returns 1 result and I can see in the dashboard that the last modified by record id (recordName) matches with the user recordName I’m sending it.

Oddly enough, using “creatorUserRecordID” and passing the same value as above does return proper results but I need lastModifiedBy.

EDIT: Per the suggestions I tried to use the actual userCKRecord.recordName as a string and sending this predicate to CloudKit.

lastModifiedPred = NSPredicate(format: "lastModifiedUserRecordID = %@", userCKRecord.recordName)

and received this error:

“Field ‘___modifiedBy’ has a value type of REFERENCE and cannot be
queried using filter value type STRING”

As I mentioned above, I can query creatorUserRecordID just fine using the original predicate at the top (using CKRecord.ID), but it just doesn’t work for lastModifiedUserRecordID.

My conclusion is that Apple is preventing this and it’s simply not possible.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.