How to request a user in CloudKit?

I want to query for all entries created by the current user. I can successfully get the CKRecordID of the current user, but I cannot request it correctly. Below is the code I'm using. What am I doing wrong?

[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"creatorUserRecordID = %@", recordID];
     CKQuery *query = [[CKQuery alloc] initWithRecordType:@"MyEntity" predicate: predicate];
     [database performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
           //results are empty       
      }];
}];

By the way, I created some "MyEntity" records in the database.

+4
source share
1 answer

If you look at your record type in the CloudKit Dashboard and open the Metadata Index drop-down field, you will see that none of them are searchable. Until yesterday they were. This morning I noticed this because I could no longer sort by createDate using:

[NSSortDescriptor(key: "creationDate", ascending: false)]

, CloudKit, . , . , CloudKit 0 .

update: , . , . creatorUserRecordID . , , . . , : https://github.com/evermeer/EVCloudKitDao

+3

All Articles