2014-07-21 53 views
0

我的方案: 我有公用数据库中某个记录类型的记录列表。当某人按下按钮时,我只想显示“示例”键中包含值“1”的记录。任何想法如何做到这一点,而CKRecords阵列正在创建?这是我目前如何构建阵列:按键值过滤CKQuery

- (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); 
     } 
    }]; 
} 

谢谢!

回答

0

你可以尝试

CKQuery *查询= [[CKQuery页头] initWithRecordType:@ “NewArticle” 谓词:[NSPredicate predicateWithFormat:@ “示例== 1”]];

NSPredicate Programming Guide