I am trying to convert CKRecords downloaded from cloudkit back to the original form of data they were (in this case a CLLocation). I get the error "Cannot convert value of type 'CKRecord' to expected argument type 'CLLocation'" when I try to call the function on line 17.
func loadLocation(completion: (error:NSError?, records:[CKRecord]?) -> Void)
{
let query = CKQuery(recordType: "Location", predicate: NSPredicate(value: true))
CKContainer.defaultContainer().publicCloudDatabase.performQuery(query, inZoneWithID: nil){
(records, error) in
if error != nil {
print("error fetching locations: \(error)")
completion(error: error, records: nil)
} else {
print("found locations: \(records)")
completion(error: nil, records: records)
guard let records = records else {
return
}
for(var i = 0; i<records.count; i += 1)
{
addBoundry(records[i])
}
}
}
}
Save your record by setting a key of the record to your location:
recordThatYouAreSaving.setObject(yourLocation, forKey: "location")
Then to get it:
addBoundry(records[i]["location"] as! CLLocation)