iosarraysswiftcloudkitckrecord

How can I fetch all records from cloudkit


I am having trouble getting my application to fetch all of one type of record and have each users record put into an array.

this is the code that saves the record

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

Solution

  • You'll need to use a CKQuery with a NSPredicate set to true:

    let predicate = NSPredicate(value: true)
    
    let query = CKQuery(recordType: "location", predicate: predicate)
    
    database?.performQuery(query, inZoneWithID: nil) { results, error in
        //...
    }