我有一个recordID.recordName(在这个例子中是singleID),我想用queryOp查询;经过一些搜索和实验后,我设法将这段代码放在一起......这可行,但它真的正确吗,也许有更短的路径。
CKRecordID *wellKnownIDx = [[CKRecordID alloc] initWithRecordName:singleID];
CKReference *singleREX = [[CKReference alloc] initWithRecordID:wellKnownIDx action:CKReferenceActionDeleteSelf];
CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:@"iCloud.blah"] publicCloudDatabase];
NSPredicate *predicatex = [NSPredicate predicateWithFormat:@"recordID == %@",singleREX];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Courses" predicate:predicatex];
CKQueryOperation *queryOp =[[CKQueryOperation alloc] initWithQuery:query];
queryOp.desiredKeys = @[@"record.recordID.recordName"];
queryOp.resultsLimit = 1;
queryOp.recordFetchedBlock = ^(CKRecord *results)
{
NSLog(@"Student Found %@",results.recordID.recordName);
};
queryOp.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
{
NSLog(@"CKQueryCursor error %@", error);
};
[publicDatabase addOperation:queryOp];