如何从 cloudkit 中获取所有记录

How can I fetch all records from cloudkit

我无法让我的应用程序获取所有一种类型的记录并将每个用户记录放入一个数组中。

这是保存记录的代码

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
   let id = CKRecordID(recordName: "01")
   let locationRecord = CKRecord(recordType: "location", recordID: id)
   locationRecord.setObject(location, forKey: "location")
   let publicData = CKContainer.defaultContainer().publicCloudDatabase
   publicData.saveRecord(locationRecord) { record, error in
     //..
   }
}

您需要使用 CKQuery 并将 NSPredicate 设置为 true:

let predicate = NSPredicate(value: true)

let query = CKQuery(recordType: "location", predicate: predicate)

database?.performQuery(query, inZoneWithID: nil) { results, error in
    //...
}
CKDatabase *publicDatabase = [[CKContainer defaultContainer]];

NSPredicate *predicate = [NSPredicate predicateWithValue:YES];

CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Group_attributes"];

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

}];

NSPredicate *predicate = [NSPredicate predicateWithValue:YES]; CKQuery *query = [[CKQuery alloc] initWithRecordType:ckEventsRecord predicate:predicate];

[[CloudKitManager publicCloudDatabase] performQuery:query
                            inZoneWithID:nil
                       completionHandler:^(NSArray *results, NSError *error) {
                           NSLog(@"%@",results);
                           NSLog(@"%@",error);

                            [arrTemp addObjectsFromArray:results];




                           }];