我正在尝试使用orderByDescending("createdAt")
从parse.com发出检索数据的订单。我的代码如下:
var postQuery:PFQuery = PFQuery(className: "Posts")
postQuery.whereKey("postedBy", equalTo: followedUser)
postQuery.orderByDescending("createdAt")
postQuery.findObjectsInBackgroundWithBlock ({ (objects, error) -> Void in
if let objects = objects {
for object in objects {
println(object.createdAt)
if let post = object as? PFObject {
self.data.addObject(object)
但它不起作用..数据以随机顺序出现。
println(object.createdAt
给出:
Optional(2015-08-25 22:25:36 +0000)
Optional(2015-08-24 13:39:25 +0000)
Optional(2015-08-25 22:28:28 +0000)
Optional(2015-08-24 13:40:48 +0000)
我的完整代码是:
func loadData() {
var followersQuery : PFQuery = PFQuery(className: "Followers")
followersQuery.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
followersQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let followers = objects {
for users in followers {
var followedUserId = users["user"] as! String
println(followedUserId)
var postQuery:PFQuery = PFQuery(className: "Posts")
postQuery.orderByDescending("createdAt")
postQuery.whereKey("postedBy", equalTo: followedUserId)
postQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects {
for object in objects {
println(object.createdAt)
self.data.addObject(object)
// println(self.data)
}
}
})
}
}
}
}
感谢您的时间。