1

我试图弄清楚如何使用 Objective-C 在 cloudkit 中查询我的记录索引。我构建了一个查询来获取我的所有记录:

CKContainer *container = [CKContainer containerWithIdentifier:containerID];
CKDatabase *publicDatabase = [container publicCloudDatabase];
CKQuery *query = [[CKQuery alloc] initWithRecordType:recordType
                                           predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];
[publicDatabase performQuery:query
                inZoneWithID:nil
           completionHandler:^(NSArray *results, NSError *error)
 {

     if (!error)
     {
     NSLog(@"results query %@", results);

     }

     else
     {
         NSLog(@"FETCH ERROR: %@", error);
     }
 }];

但我需要获取每条记录的索引。你们中的任何人都知道如何只能查询所有记录的索引吗?

我会非常感谢你的帮助

4

2 回答 2

2

而不是 CKQuery 使用 CKQueryOperation。然后,您可以设置 desiredKeys 属性以将结果限制为仅 id。你可以使用类似的东西:

    CKContainer *container = [CKContainer containerWithIdentifier:containerID];
    CKDatabase *publicDatabase = [container publicCloudDatabase];
    CKQuery *query = [[CKQuery alloc] initWithRecordType:recordType
                                               predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];
    CKQueryOperation *queryOp = [[CKQueryOperation alloc] initWithQuery:query];
    queryOp.desiredKeys = @[@"record.recordID.recordName"];
    queryOp.recordFetchedBlock = ^(CKRecord *record)
    {
        // do something...
    };

     queryOp.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
    {
        // do something else...
    };

    queryOp.resultsLimit = CKQueryOperationMaximumResults;
    [publicDatabase addOperation:queryOp];
于 2014-12-01T09:09:30.990 回答
0

这是 Objective-C 的答案:

 CKContainer *container = [CKContainer containerWithIdentifier:containerID];
    CKDatabase *publicDatabase = [container publicCloudDatabase];
    CKQuery *query = [[CKQuery alloc] initWithRecordType:recordType
                                               predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];
     CKQueryOperation *queryOp = [[CKQueryOperation alloc] initWithQuery:query];
    queryOp.desiredKeys = @[@"record.recordID.recordName"];
    queryOp.recordFetchedBlock = ^(CKRecord *record)
    {
        // do something...
    };

     queryOp.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
    {
        // do something else...
    };

    queryOp.resultsLimit = CKQueryOperationMaximumResults;
    [publicDatabase addOperation:queryOp];
于 2014-12-01T19:12:06.210 回答