我有一个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];
答案 0 :(得分:0)
你有什么应该工作,但看起来你想要做的就是获取一个已知recordID的记录。没有必要使用查询。它的代码多于必要的代码,并且还需要在该字段上使用查询索引。
相反,在CKDatabase上使用fetchRecordWithID方法: https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKDatabase_class/index.html#//apple_ref/occ/instm/CKDatabase/fetchRecordWithID:completionHandler: