0

我的场景:我在公共数据库中有一个特定记录类型的记录列表。当有人按下按钮时,我只想显示“示例”键中包含值“1”的记录。知道如何在创建 CKRecords 数组时执行此操作吗?这就是我目前构建数组的方式:

- (void)queryCloudKit
{
    CKQuery *query = [[CKQuery alloc] initWithRecordType:@"NewArticle"
                                               predicate:[NSPredicate predicateWithValue:YES]];
    query.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"Date" ascending:NO]];

    [self.publicDatabase performQuery:query
                         inZoneWithID:nil
                         completionHandler:^(NSArray *results, NSError *error) {

        if (!error) {
            // CK convenience methods completion
            // arent executed on the callers thread.
            // more info: http://openradar.appspot.com/radar?id=5534800471392256
            @synchronized(self){
                self.results = [results mutableCopy];
                // make sure it executes on main thread
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.collectionView reloadData];
                });
            }
        }
        else {
            NSLog(@"FETCH ERROR: %@", error);
        }
    }];
}

谢谢!

4

1 回答 1

0

你可以试试

CKQuery *query = [[CKQuery alloc] initWithRecordType:@"NewArticle" 谓词:[NSPredicate predicateWithFormat:@"Example == 1"]];

NSPredicate 编程指南

于 2014-07-22T16:18:38.187 回答