我将PFObject数组合并到了Parse ......
array.appendContentsOf(otherArray)
如何创建这个大数组并在创建时将其组织起来?
基本上我的查询是什么,我拿出了大部分东西并改变了一些东西,所以如果你没有看到我的整个班级就有意义......
func loadStuff() {
let postQuery = PFQuery(className: "Post")
postQuery.orderByDescending("createdAt")
postQuery.whereKey("type", equalTo: "world")
postQuery.whereKey("distance", equalTo: distanceType)
postQuery.whereKey("location", nearGeoPoint: PFGeoPoint(location: currentLocation), withinMiles: miles)
postQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects as? [PFObject] {
// Remove content from arrays if it's the first query
if error == nil {
if arrayOfPosts.isEmpty == false {
for post in arrayOfPosts {
// Append stuff
if queryIsComplete == true {
if query == 0 {
self.loadStuff()
} else if query == 1 {
self.loadStuff()
} else {
self.arrays.appendContentsOf(self.arrayFromQuery1)
self.arrays.appendContentsOf(self.arrayFromQuery2)
self.arrays.appendContentsOf(self.arrayFromQuery3)
self.arrays.sortInPlace({ $0.createdAt!.compare($1.createdAt!) == NSComparisonResult.OrderedAscending })
self.table.reloadData()
}
}
}
}
}
}
})
}
答案 0 :(得分:2)
我假设你异步获取大量记录,所以:
array.sortInPlace { $0.createdAt.compare($1.createdAt) == NSComparisonResult.OrderedAscending }
答案 1 :(得分:0)
如果你想知道在数组中创建每个对象的时间,你将在使用时间戳createAt
或updateAt
var timeStamp = NSDate(timeIntervalSinceNow: -1200)
query.whereKey("createdAt", greaterThanOrEqualTo: timeStamp)
然后您可以像下面的
一样订购您的列表 query.orderByDescending("createdAt") //either Ascending or Descending
所以现在你将做我的朋友@DavidWong提议进入最高职位:)