我将从 Parse 获得的 PFObject 数组组合在一起......
array.appendContentsOf(otherArray)
我将如何使用这个大数组并根据它们的创建时间对其进行组织?
这基本上是我的查询内容,我删除了大部分内容并更改了一些内容,因此如果您没有看到我的整个类(class),这将是有意义的...
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()
}
}
}
}
}
}
})
}
最佳答案
我假设您正在异步获取大量记录:
array.sortInPlace { $0.createdAt.compare($1.createdAt) == NSComparisonResult.OrderedAscending }
关于ios - 按日期解析的有组织的组合数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987380/