Unable to complete request based on user id in Cloudkit

I don't understand why my ckquery is not fetching user generated entries. Here is my code:

@IBAction func browseMyComplaints(sender: AnyObject) {
    // who am i?
    CKContainer.defaultContainer().fetchUserRecordIDWithCompletionHandler({ userRecordID, error in
        if error == nil {
            let query:CKQuery = CKQuery(recordType: "myComplaint", predicate: NSPredicate(format: "creatorUserRecordID = %@", userRecordID))

            var results : [CKRecord] = [CKRecord]()
            var operation : CKQueryOperation = CKQueryOperation(query: query)

            operation.recordFetchedBlock = { (record:CKRecord!) -> Void in

            operation.queryCompletionBlock = {
                (cursor:CKQueryCursor!, error:NSError!) in
                if (error != nil) {
                } else {
                    NSLog("no query error reported")
                    NSLog(String(results.count) + " found")
                    tvComplaintRecords = results
                    self.performSegueWithIdentifier("complaintList", sender: self)

        } else {
            println("Can not identify user due to error: \(error.localizedDescription)")




My conclusion:

<CKRecordID: 0x7be3f220; _46761404769b094e82053fea39b16bb5:(_defaultZone:__defaultOwner__)>
2014-10-11 12:45:32.597 ReportAMenace[15244:781048] no query error reported
2014-10-11 12:45:32.597 ReportAMenace[15244:781048] 0 found


But there are 11 entries including 1 that I made before I did the above query. Any hints?


source to share

2 answers

I understand it. Of course, there was a simple answer, although even then it was not completely straightforward.

I needed to log into the Cloudkit Dashboard (online site) and provide a creator field etc. if the request flag was set.

However, even then the old ones did not appear (perhaps they will be later if Cloudkit does some nightly batch indexing, not sure). But IT DID WORK for new records created from now on.



You can create a CKQuery to find the record id like this:

var query = CKQuery(recordType: recordType, predicate: NSPredicate(format: "%K == %@", "creatorUserRecordID" ,CKReference(recordID: userRecordID, action: CKReferenceAction.None)))




All Articles