2014-07-21 51 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