Caleb Caleb - 1 year ago 92
Swift Question

Trying to use the original form of data from a CKRecord in Swift

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 {
for(var i = 0; i<records.count; i += 1)

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download