gpt4 book ai didi

ios - CloudKit:查询索引(recordID.recordName)

转载 作者:行者123 更新时间:2023-11-29 10:35:48 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 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);
}
}];

但是我需要获取每条记录的索引。大家知道怎么只能查询所有记录的索引吗?

非常感谢你的帮助

最佳答案

使用 CKQueryOperation 代替 CKQuery。然后您可以设置 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];

关于ios - CloudKit:查询索引(recordID.recordName),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27223957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com