按键值过滤CKQuery

时间:2014-07-21 13:52:05

标签: ios ios8 icloud cloudkit ckquery

我的情景: 我有一个公共数据库中某种记录类型的记录列表。当有人按下按钮时,我想只显示包含值" 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);
        }
    }];
}

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试

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

NSPredicate Programming Guide