我的查询看起来像这样:
IPublishBus
NSDate扩展:
func QueryImagesFromParse(){
var query = PFQuery(className: "Posts")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil
{
if let newObjects = objects as? [PFObject] {
for oneobject in newObjects {
var text = oneobject["imageText"] as! String
var username = oneobject["username"] as! String
var time = oneobject.createdAt
var userImageFile = oneobject["imageFile"] as! PFFile
userImageFile.getDataInBackgroundWithBlock({ (imageData:NSData?, error:NSError?) -> Void in
if error == nil {
let newImage = UIImage(data: imageData!)
var OneBigObject = Details(username: username, text: text, CreatedAt: time!, image: newImage!)
self.arrayOfDetails.append(OneBigObject)
self.collectionView.reloadData()
}
})
}
}
}
}
}
我已尝试使用extension NSDate {
var timeAgo: String {
let minute = 60
let hour = 60 * minute
let day = 24 * hour
let secondsAgo = Int(NSDate().timeIntervalSinceDate(self))
if secondsAgo < 0 { return "later" }
if secondsAgo == 0 { return "now" }
if secondsAgo == 1 { return "1 second ago" }
if secondsAgo < minute { return "\(secondsAgo) seconds ago" }
if secondsAgo < (2 * minute) { return "1 minute ago" }
if secondsAgo < hour { return "\(secondsAgo/minute) minutes ago" }
if secondsAgo < 2 * hour { return "1 hour ago" }
if secondsAgo < day { return "\(secondsAgo / hour) hours ago" }
let formatter = NSDateFormatter()
formatter.dateFormat = "M/d/yy"
return formatter.stringFromDate(self)
}
}
对最新上传的内容进行排序,但它不起作用。上传按随机顺序排列,而不是最新的。我究竟做错了什么?我在viewDidLoad中运行query.orderByDescending
。