如何从cloudkit中获取所有记录

时间:2016-07-09 17:22:10

标签: ios arrays swift cloudkit ckrecord

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

这是保存记录的代码

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
     //..
   }
}

3 个答案:

答案 0 :(得分:5)

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

let predicate = NSPredicate(value: true)

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

database?.performQuery(query, inZoneWithID: nil) { results, error in
    //...
}

答案 1 :(得分:-1)

CKDatabase *publicDatabase = [[CKContainer defaultContainer]];

NSPredicate *predicate = [NSPredicate predicateWithValue:YES];

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

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

}];

答案 2 :(得分:-1)

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

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

                            [arrTemp addObjectsFromArray:results];




                           }];