Retrieving just one value from a Record in CloudKit
<p>I'm learning to use CloudKit and finally managed to retrieve/query data hard coded into the dashboard. I'm trying to query only one value from a record using a <code>CKQueryOperation</code> but I always receive all the values in each and every record.
In my code below I'm trying to get just the "age" values by using the <code>desiredKey</code> property - what I get back is "age", "firstName", "lastName" etc etc.</p>

<pre><code>let container = CKContainer.defaultContainer()
let publicData = container.publicCloudDatabase

// select all records
let predicate = NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)
let query = CKQuery(recordType: "quizRecord", predicate: predicate)

// get just one value only
let operation = CKQueryOperation(query: query)
operation.desiredKeys = ["age"]


   // addOperation
    publicData.addOperation(operation)

publicData.performQuery(query, inZoneWithID: nil) { results, error in
    if error == nil { // There is no error
        // PROBLEM .. this prints out all values ????
        print(results)
        dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
        })
    }
    else {
        print(error)
    }
}
</code></pre>

<p>//// The following / amended code works fine</p>

<pre><code>    let container = CKContainer.defaultContainer()
    let publicData = container.publicCloudDatabase

    // select all records
    let predicate = NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)
    let query = CKQuery(recordType: "quizRecord", predicate: predicate)

    // get just one value only
    let operation = CKQueryOperation(query: query)
    operation.desiredKeys = ["age"]


    // get query
    operation.recordFetchedBlock = { (record : CKRecord) in
        // process record

        print(record)

    }


    // operation completed
    operation.queryCompletionBlock = {(cursor, error) in
        dispatch_async(dispatch_get_main_queue()) {
            if error == nil {

                print("no errors")
                // code here

            } else {

                print("error description = \(error?.description)")
            }
        }
    }

        // addOperation
    publicData.addOperation(operation)
</code></pre>