Swift Sorting通过createdAt解析结果

时间:2015-08-27 15:22:07

标签: ios swift parse-platform

我查询存储在parse.com上的消息

let query = PFQuery(className: "Messages")
    query.whereKey("sender", equalTo: self.sender)
    query.whereKey("receiver", equalTo: self.receiver)
    query.orderByAscending("createdAt")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            var messages = [Int: [AnyObject]]()

            if let objects = objects as? [PFObject] {
                var i: Int = 0
                for object in objects {

                    var temp = [AnyObject]()

                    temp.append(object["sender"]!)
                    temp.append(object["receiver"]!)
                    temp.append(object.createdAt!)
                    temp.append(object["message"]!)

                    messages[i] = temp

                    i = i+1
                }
                print("Messages: \(messages)")
            }
        } else {
            print("Error!")
        }
    }

结果如

  消息:[2:[Phil,Eff,2015-08-27 15:05:04 +0000,three],0:[Phil,Eff,2015-08-27 15:04:57 +0000,one ],1:[Phil,Eff,2015-08-27 15:05:00 +0000,two]]

似乎query.orderByAscending("createdAt")无所事事?

0 个答案:

没有答案