Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudKit: Order query results by creation date

When loading items from CloudKit I would like to order the results by creation date. I believe now it's sorting by the first property of the record.

func loadItems() {
    let predicate = NSPredicate(value: true)
    let query = CKQuery(recordType: "Items", predicate: predicate)
    db.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
        if error != nil {
            println(error.localizedDescription)
        }

        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            items = results as [CKRecord]
            self.tableView.reloadData()
            println("items: \(items)")
        }
    }
}
like image 573
colindunn Avatar asked Feb 01 '15 21:02

colindunn


1 Answers

This is what I was looking for:

query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
like image 141
colindunn Avatar answered Oct 08 '22 08:10

colindunn