1

I am trying to have all the users' locations stored in cloudkit, then downloaded by each device. I marked on the code in storeLocation where I get the error:

"Cannot convert value of type '(NSError?, [CKRecord]?)' (aka '(Optional, Optional>)') to expected argument type '(error: NSError?, records: [CKRecord]?) -> Void'"

//saves location in cloud kit //currently works well:

var locArray = [CKRecord]()
func storeLocation(location:CLLocation) {
        let locationRecord = CKRecord(recordType: "location")
        locationRecord.setObject(location, forKey: "location")
        let publicData = CKContainer.defaultContainer().publicCloudDatabase
        publicData.saveRecord(locationRecord) { (records, error) in
            if error != nil {
                print("error saving locations: \(error)")
            } else {
                print("Locations saved: \(records)")
                loadLocation((error, self.locArray)) //where I get error******
            }
        }
    }

//fetches location from cloud kit:

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")
            completion(error: error, records: nil)
        } else {
            print("found locations: \(records)")
            completion(error: nil, records: records)
        }
    }
}
1
  • I answered this on your original question @caleb. :) Commented Aug 18, 2016 at 2:10

1 Answer 1

2

I believe instead of:

loadLocation((error, self.locArray))

You need to call this:

loadLocation() { (error, records) in
    // do something here with the returned data.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.